About Directory web project problems

  • Give the code section:
		// 初始化阶段,读取new_words.txt
		// web工程中读取 文件,必须使用绝对磁盘路径
		String path = getServletContext().getRealPath("/WEB-INF/new_words.txt");
		System.out.println(path);
//		path = "C:\\Users\\admin\\IdeaProjects\\webDemo\\firstWeb\\web\\WEB-INF\\new_words.txt ";
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
			String line;
			while ((line = reader.readLine()) != null) {
				words.add(line);
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

  • This code has been above mistakes, I do not know the reason behind the non-stop to find information found the problem: my web project output directory there is a problem, because I am also the first time with the idea to write web project, we found a lot of bug
    Here Insert Picture Description
  • In fact, there is no problem, we need to note is that you must have this file in the output folder out, out the output folder by default filtering these files
    Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_42479155/article/details/90314652