在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  的告知

猜你喜欢

转载自my.oschina.net/u/4010699/blog/2396151
今日推荐