Where to put a textfile I want to use in eclipse?
Posted
by Jayomat
on Stack Overflow
See other posts from Stack Overflow
or by Jayomat
Published on 2010-05-17T16:04:33Z
Indexed on
2010/05/17
17:00 UTC
Read the original article
Hit count: 360
hi there,
I need to read a text file when I start my program. I'm using eclipse and started a new java project. In my project folder I got the "src" folder and the standard "JRE System Library"... I just don't know where to put the text file. I cannot use a "hard coded" path because the text file needs to be included with my app...
I also tried to create a new folder like "Files" and use the pathe "Files/staedteliste.txt".. doesn't work too...
I use the following code to read the file, but I get this error:
Error:java.io.FileNotFoundException:staedteliste.txt(No such file or directory)
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class Test {
ArrayList<String[]> values;
public static void main(String[] args) {
// TODO Auto-generated method stub
loadList();
}
public static void loadList() {
BufferedReader reader;
String zeile = null;
try {
reader = new BufferedReader(new FileReader("staedteliste.txt"));
zeile = reader.readLine();
ArrayList<String[]> values = new ArrayList<String[]>();
while (zeile != null) {
values.add(zeile.split(";"));
zeile = reader.readLine();
}
System.out.println(values.size());
System.out.println(zeile);
} catch (IOException e) {
System.err.println("Error :"+e);
}
}
}
thx for help!
© Stack Overflow or respective owner