我正在读取的文件未获取。我不知道这是否与我正在使用的操作系统有关,但是请告诉我,我在macOs环境中。无论如何,我都有这个.txt文件,正在将其路径传递给类“ File”的构造函数。我正在使用条件测试它是否存在,我收到一条消息“文件不存在”。我对为什么没有实现感到困惑。
try {
File file = new File("StudentInfo.txt");
if (file.exists()) {
System.out.println("File found");
} else {
System.out.println("File not found");
}
} catch (SecurityException se) {
se.printStackTrace();
}
}
答案 0 :(得分:0)
打开一个Finder窗口,转到文件StudentInfo.txt,用鼠标选择该文件,然后按ALT键,然后右键单击并选择“将StudentInfo.txt复制为路径名”。之后,剪贴板中便有了该文件的完整路径。
或者,使用终端,使用sudo apt-get install -y mongodb-org=3.4.10 mongodb-org-server=3.4.10 mongodb-org-shell=3.4.10 mongodb-org-mongos=3.4.10 mongodb-org-tools=3.4.10
命令转到包含文件的目录,然后键入E: Version '3.4.10' for 'mongodb-org' was not found
E: Version '3.4.10' for 'mongodb-org-server' was not found
E: Version '3.4.10' for 'mongodb-org-shell' was not found
E: Version '3.4.10' for 'mongodb-org-mongos' was not found
E: Version '3.4.10' for 'mongodb-org-tools' was not found
以获取当前路径。