如何设置FileOutputStream的变量路径?
我的代码现在:
System.out.print("Please insert name");
String fileName = scan.nextline();
path = System.getProperty("user.home") + "\\Desktop";
FileOutputStream fileOut = new FileOutputStream(path + fileName + ".xlsx");
但这不起作用。 你有什么建议吗?
答案 0 :(得分:1)
在第path = System.getProperty("user.home") + "\\Desktop";
行(或FileOutputStream fileOut = new FileOutputStream(path + fileName + ".xlsx");
变量与path
变量之间的行fileName
)的末尾,您应添加\
因为您的文件将被称为C:\Users\You\Desktopaaaaaa.xlsx
而不是C:\Users\You\Desktop\aaaaaa.xlsx
(请参阅缺少的反斜杠?)并且不会在所需位置...