看板 java 關於我們 聯絡資訊
※ 引述《ogre0403 (肚子餓)》之銘言: : 我用Properties來讀我的設定檔,可是很奇怪的是我只打檔名會出現 : FileNotFoundException, : 例如:props.load(new FileInputStream("table.prop")); : 可是假如我打出完整的路徑就可以了 : 例如: : props.load(new FileInputStream : ("D:\\JAVA\\workspace\\Project_test\\src\\table.prop")); : 我是用eclipse,property檔和其他檔都放在同個目錄下, : 有人有遇過這個奇怪的問題嗎 這和Properties沒關係吧。 你應該有發現你處理的class叫做 FileInputStream, 然後也應該去查一下這個class的API試試看能不能碰碰運氣。 我是這麼做了,然後我發現這段話。 Creates a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system. A new FileDescriptor object is created to represent this file connection. First, if there is a security manager, its checkRead method is called with the name argument as its argument. If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown. (引用自) http://0rz.tw/0f2sN 後來你發現了打出絕對路徑就可以了。 所以這表示 %default%/table.prop != D:/JAVA/.../src/table.prop 然後我們又知道可以自己create出一個File物件來確認看看。 因為FileStream從API也就是做這件事情嘛! 於是我寫下 File f_relative=new File("table.prop"); System.out.println(f_relative.getAbsolutePath()); 然後我再寫下 File f_absolute= new File("D:/JAVA/workspace/Project_test/src/table.prop"); System.out.println(f_absolute.getAbsolutePath()); 所以我可以合理推論你應該會知道原因了,but who knows? XD 或者更直接一點的方式 System.out.println(System.getProperty("user.dir")); #取自骨話連篇 之『找出問題 你也可以』 -- btw,一般來說絕對路徑的正確性比較高。 -- String temp="relax"; | Life just like programing while(buringlife) String.forgot(temp); | to be right or wrong while(sleeping) brain.setMemoryOut(); | need not to say stack.push(life.running); | the compiler will stack.push(scouting.buck()); | answer your life stack.push(bowling.practice()); | Bone everything -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.27.68