Tôi cố gắng để đọc một tập tin và các lỗi tôi nhận được làFileNotFoundException khi tập tin tồn tại với tất cả các quyền
java.io.FileNotFoundException: /homes/at1106/fourthYearComputing/Individual-Project/svn-workspace/trunk/Individual_Project/src/game/player/gametheoryagent/configurations/gameTheoryAgentConfiguration.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at game.player.gametheoryagent.GameTheoryAgent.<init>(GameTheoryAgent.java:67)
at simulation.Simulator.createPlayer(Simulator.java:141)
at simulation.Simulator.main(Simulator.java:64)
tuy nhiên các tập tin không tồn tại và chỉ để kiểm tra tăng gấp đôi tôi đã cho nó 777 điều khoản, như hình dưới đây:
tui% cd /homes/at1106/fourthYearComputing/Individual-Project/svn-workspace/trunk/Individual_Project/src/game/player/gametheoryagent/configurations
tui% ls -al
total 4
drwxrwxrwx 3 at1106 cs4 1024 2010-02-22 17:45 .
drwxrwxrwx 4 at1106 cs4 1024 2010-02-22 17:27 ..
-rwxrwxrwx 1 at1106 cs4 260 2010-02-22 17:31 gameTheoryAgentConfiguration.properties
drwxrwxrwx 6 at1106 cs4 1024 2010-02-22 17:41 .svn
Bất kỳ ý tưởng nào về lý do tôi nhận ngoại lệ FNF?
Cảm ơn
đangjava mà làm cho các cuộc gọi:
File file = new File(pathToConfiguration)
Properties configuration = new Properties();
try{
configuration.load(new FileInputStream(file));
int RAISE_RATIO = Integer.parseInt(configuration.getProperty("raise_ratio"));
}
catch(IOException event){
System.err.println("Error in reading configuration file " + pathToConfiguration);
event.printStackTrace();
}
Các tập tin thuộc tính đọc:
raise_ratio=4
này đã được thử nghiệm trong các cửa sổ (với một pathToConfiguration diff (được thông qua vào các nhà xây dựng)) và hoạt động tốt.
gia tăng trong kiểm tra sau đây trong khối Catch
if(file.exists()){
System.out.println("file exists");
}
else{
System.out.println("file doesn't exist");
}
System.out.println(file.getAbsolutePath());
if(file.canRead()){
System.out.println("can read");
}
if(file.canWrite()){
System.out.println("can write");
}
đầu ra như sau:
file doesn't exist
/homes/at1106/fourthYearComputing/Individual-Project/svn-workspace/trunk/Individual_Project/src/game/player/gametheoryagent/configurations/gameTheoryAgentConfiguration.properties
Bạn có thể dán mã Java thực tế không? – Martin
Bạn đang chạy mã nào khi ngoại lệ được ném? Điều gì xảy ra nếu bạn sử dụng file.exists()? file.getAbsolutePath()? file.canRead/Write/Execute()? – Pops
Bạn có đang chạy mã java trên cùng một máy nơi tệp tồn tại không? –