在Windows下的路徑分隔符和Linux下的路徑分隔符是不一樣的

比如說要在temp目錄下建立一個test.txt文件,在Windows下應該這麼寫:
File file1 = new File ("C:\tmp\test.txt");
在Linux下則是這樣的:
File file2 = new File ("/tmp/test.txt");

如果要考慮跨平臺,則最好是這麼寫:
File myFile = new File("C:" + File.separator + "tmp" + File.separator, "test.txt");
 

String zip = savePath + File.separator + Common.QRCODE + File.separator + subpath +File.separator + batchCode + Common.ZIP;

windows linux 都寫成 /temp 這樣的也是可以的  謝謝 yanek  的告知

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章