"I saved the text1.txt file in the same folder as the Algo.java file is in. But i get a Filenotfoundexception and i can't find any reason for that"
Then read the file from the class path. You can get an InputStream
from Algo.class.getResourceAsStream()
InputStream is = Algo.class.getResourceAsStream("text1.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
When you try to read it as a File
, which is the case when use FileReader(String path)
, file will be search within the file system, and in your IDE the search will begin from the working directory that is specified (normally the project root). So for the FileReader
to work, with just the name of the file passed, the file should be in the working directory.
Depending on the requirements, whether the application is specific to your system or should be distributed on other systems, you need to make the decision whether the file should be read from the class path, or the file system.