输出的可变路径?

时间:2015-04-23 13:50:37

标签: java

如何设置FileOutputStream的变量路径?

我的代码现在:

System.out.print("Please insert name");
String fileName = scan.nextline();
path = System.getProperty("user.home") + "\\Desktop";
FileOutputStream fileOut = new FileOutputStream(path + fileName + ".xlsx");

但这不起作用。 你有什么建议吗?

1 个答案:

答案 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(请参阅缺少的反斜杠?)并且不会在所需位置...