[英]finding the path of file in a Java program
在以下Java程序中(僅顯示整個程序的一部分),我具有以下代碼:
private final File test_data_file;
private final int algorithm_selection;
private double average_pos_err, average_exe_time;
// The scan list to use for offline
private ArrayList<LogRecord> OfflineScanList;
public OfflineMode(RadioMap RM, File test_data_file, int algorithm_selection, Handler handler) {
this.RM = RM;
this.test_data_file = test_data_file;
this.handler = handler;
this.algorithm_selection = algorithm_selection;
this.OfflineScanList = new ArrayList<LogRecord>();
}
public void run() {
if (!test_data_file.isFile() || !test_data_file.exists() || !test_data_file.canRead()) {
errMsg = test_data_file + " does not exist or is not readable";
handler.sendEmptyMessage(-1);
return;
}
我想查找File類型的變量“ test_data_file”的路徑,但是代碼似乎沒有顯示任何方向。 你知道我在哪里可以找到它嗎?
謝謝。
您可以使用File#getAbsolutePath或File#getCanonicalPath來完全解析路徑(刪除相關組件)
通過Java 7使用可以獲取文件類型
String fileType = Files.probeContentType(test_data_file.getPath());
有關更多詳細信息,請參考http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#probeContentType%28java.nio.file.Path%29
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.