【发布时间】:2015-09-13 18:18:06
【问题描述】:
我有一个特定的要求,我需要将文件从 Unix 服务器复制到 Windows 共享驱动器。我正在用 Java 开发必要的代码。我是初学者,所以请原谅这个基本问题。
我的配置文件中有我的源路径。所以,我使用下面的代码来导入我的配置文件并设置我的变量。我的项目附加了 config.properties 文件。
public static String rootFolder = "";
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("config.properties");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("Config files not able to set properly for Dest Folder");
}
try {
prop.load(input);
rootFolder = prop.getProperty("Dest_Root_Path");
System.out.println("Destination Folder is being initialized to - "+rootFolder);
} catch (IOException e) {
e.printStackTrace();
System.out.println("Destination Path not set properly");
}
执行此操作时,我收到一条错误消息,提示找不到文件。
java.io.FileNotFoundException: config.properties (No such file or directory)
at java.io.FileInputStream.<init>(FileInputStream.java:158)
at java.io.FileInputStream.<init>(FileInputStream.java:113)
Exception in thread "main" java.lang.NullPointerException
at java.util.Properties.load(Properties.java:357)
我正在使用 unix ksh shell 触发这个 jar。请给我指导。
【问题讨论】:
-
config.properties在您的项目中位于何处? -
它存在于与其他文件类似的文件夹结构中。我没有单独的这个配置文件的任何文件夹结构。我刚刚右键单击我的项目并创建了一个文件并输入了我需要的详细信息。当我在本地运行代码时,它工作正常。但是当我从服务器运行它时,我收到了这个错误。
-
你在使用一些 IDE 吗?您是否为该文件创建了一个源文件夹?如果是,那么您是否尝试过类似'input = NameOfClass.class.getResourceAsStream(“config.properties”);'....
-
nlcE cOw,- 是的,我正在使用 RAD 进行代码开发。我还没有创建任何这样的文件夹。我没有用过这种方法。
-
“但是当我从服务器运行它时,我得到了这个错误。” - 服务器上的配置文件在哪里?
标签: java linux nullpointerexception filenotfoundexception