【发布时间】:2014-06-17 06:47:53
【问题描述】:
我有一个方法可以返回文件夹路径的字符串。 CSVFile 方法调用另一个方法 ConfigFilePath 从配置文件中提取值并将其返回以用于另一个条件。
public CSVFile(ManagedElement_T[] meInfo) {
String path = null;
ConfigFilePath(path);
system.out.print("CSV "+path);
}
public String ConfigFilePath(String path) {
final String directory = System.getProperty("user.dir");
final String filename = "config.properties";
final File configFile = new File(directory+"/"+filename);
final Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream(configFile);
prop.load(input);
path = prop.getProperty("diretory_csv");
System.out.println("PATH " + path);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
// Close the file
}
File checkPath = new File(path.toString());
System.out.println("CHECK " + checkPath);
if (checkPath.exists()) {
System.out.println("Directory already exists ...");
} else {
//mkdir if it does not exist
}
return path;
}
问题是,它不返回任何 var 路径?当我打印它时只是说 null 但在 ConfigFilePath 方法中,它似乎从 eclipse 中的打印中获取了正确的值。
System.out.println("PATH " + path); = C:/opt/CORBA/input
System.out.println("CHECK " + checkPath); = C:\opt\CORBA\input
System.out.print("CSV "+path); = null
【问题讨论】: