`

windows迁到linux上斜杠的问题

    博客分类:
  • java
 
阅读更多

问题描述:

String path = request.getRealPath("/budget/bugetUpload") + "\\"+ fileName; 

FileOutputStream fs = new FileOutputStream(path);

在windows中没问题,在linux中不能创建文件,也不报错,原因是linux不能识别 \

 

现改为:

String path = request.getRealPath(File.separator+"budget"+File.separator+"bugetUpload") + File.separator
    + fileName;

File.separator能够根据当前系统自动识别,在

windows是\,unix是/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics