在项目目录java上创建一个文件
我想在项目目录中创建一个文件,所以我尝试了这段代码,并在项目目录中创建了一个临时目录
try {
File file = new File("temp/"+soCourrier.getHeaders().get("filename").get(0));
FileOutputStream fos = new FileOutputStream(file);
fos.write(sCourrier.getBody());
model.addAttribute("path", file.getAbsoluteFile());
} catch (IOException e) {
e.printStackTrace();
}
但这给了我一个错误
java.io.IOException: Le chemin d’accès spécifié est introuvable
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at controllers.UserController.showCourrierDetail(UserController.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
有人能帮我吗
# 1 楼答案
似乎您在Windows计算机上使用
/
,但在Windows中,文件夹被标记为\
。 使用常量File.seperator
在每台机器上获得正确的分隔符