JAva webプロジェクトwindow/linuxリアルパス取得
汎用ツールクラス java webプロジェクトの実際のパスwindows linuxシステムを取得する:これはwebプロジェクトの中で、プロジェクトの実際のパスを取得する最良の方法で、windowsとlinuxシステムの下ですべて正常に使用することができます:
public class GetMsgCenterKey {
public static String getRootPath() {
String line=File.separator;
String path=Thread.currentThread().getContextClassLoader().getResource("").toString();
//windows
if("\\".equals(line)){
path = path.replace("/", "\\"); // / \\
path1=path+line+"excel"+line+time+".xls";
download=line+"excel"+line+time+".xls";
}
//linux
if("/".equals(line)){
path = path.replace("\\", "/");
path1=path+line+"excel"+line+time+".xls";
download=line+"excel"+line+time+".xls";
}
try {
System.out.println(" ");
out = new FileOutputStream(path1);
//ExcelAction ex=new ExcelAction();
//ex.do_ExportExcel_listmap(fleld,rs,out,dataset_fields);
//map.put("msg", "success");
} catch (FileNotFoundException e) {
System.out.println(" ");
//map.put("msg", "error");
e.printStackTrace();
}
}
System.out.println(path1);
//map.put("path", download);
return path1;
}