내가 파일 읽기 시도하고이 오류가 있습니다이상한 예외 "주"java.io.FileNotFoundException I/O 자바
Exception in thread "main" java.io.FileNotFoundException: \src\product.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at dao.Inventory.readFile(Inventory.java:30)
at view.InventoryView.init(InventoryView.java:33)
at view.InventoryView.<init>(InventoryView.java:21)
at view.InventoryView.main(InventoryView.java:211)
을하지만 것입니다, 나는 product.txt이 내 src 폴더에.
이public void readFile() throws IOException {
// input file must be supplied in the first argument
InputStream istream;
File inputFile = new File("\\src\\product.txt");
istream = new FileInputStream(inputFile);
BufferedReader lineReader;
lineReader = new BufferedReader(new InputStreamReader(istream));
String line;
while ((line = lineReader.readLine()) != null) {
StringTokenizer tokens = new StringTokenizer(line, "\t");
// String tmp = tokens.nextToken();
// System.out.println("token " + tmp);
ActionProduct p = new ActionProduct();
prodlist.add(p);
String category = p.getCategory();
category = tokens.nextToken();
System.out.println("got category " +category);
int item = p.getItem();
item = Integer.parseInt(tokens.nextToken());
String name = p.getName();
System.out.println("got name " +name);
double price = p.getPrice();
price = Double.parseDouble(tokens.nextToken());
int units = p.getUnits();
units = Integer.parseInt(tokens.nextToken());
}
}
난 아무것도 내 코드 문제라고 생각하지 않습니다 :
내 코드는 다음과 같다. 또한 FILE.TXT.TXT와 같은 숨겨진 확장에 대한 유사한 게시물을 보았습니다. 어떻게 MacOSX에서 숨겨진 확장을 표시하겠습니까 ?? 어떤 제안? (숨겨진 확장 문제 이외에 다른 문제가 있습니까?)
당신은'src에 \\ product.txt' 경로로해야한다. –
'File inputFile = new File ("./ src/product.txt"); 대신 사용해보십시오. –
또는 파일 inputFile = 새 파일 ("src \\ product.txt"); – nikhil