我試過一個程序來獲取文件名&路徑,但問題是:dPath = Path.get(path);
的Eclipse的Java獲取路徑程序
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.*;
public class Ch9_4_4 {
public static void main(String[] args) throws IOException {
String file = "Ch9_4_3.java";
String path = "temp2";
Path fPath, dPath;
fPath = FileSystems.getDefault().getPath(".", file);
dPath = Path.get(path);
System.out.println(fPath.getFileName());
System.out.println("temp2 is absolute path: "+dPath.isAbsolute());
BasicFileAttributes attr = Files.readAttributes(fPath, BasicFileAttributes.class);
if (Files.exists(fPath)) {
System.out.println("Directory: " + attr.isDirectory());
System.out.println("File: " + attr.isRegularFile());
System.out.println("Create date: " + attr.creationTime());
System.out.println("Size: " + attr.size());
}
else System.out.println("[" + fPath + "] does not exist!");
Files.createDirectory(dPath);
System.out.println("[" + dPath + "] directory is created!");
}
}
我收到以下錯誤消息:
GET方法(字符串)未定義爲類型路徑
'Paths'類包含'GET'方法其實..不'Path' –
這不是一個論壇,在這裏你可以改變的問題無效現有的(和接受)的答案。如果你有一個新的問題,然後創建一個新的問題 – Tom