我不得不返回文件夾路徑的字符串的方法。 CSVFile方法調用另一個方法ConfigFilePath提取從一個配置文件中的值,然後返回用於其他條件。Java的String返回方法不返回
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路徑?當我打印出來,但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
可能是[Java是「通過引用傳遞」還是「按值傳遞」?)(http://stackoverflow.com/questions/40480/is-java-pass-by-reference -or通按值) –