如何获取文件目录加上全名,以便我可以将其分配给变量 inFile 下面是我想读取的数据类型我使用了正则表达式但它不起作用
public void loadAfileFinal() throws FileNotFoundException
{
Fiog fileBox = new FileD(ileDialog);
fox.sVisle(true);
while(scanner.hasNext())
{
String name = scanner.nextLine();
System.out.println(name);
}
}
最佳答案
阅读File
's JavaDoc 。以下是您应该考虑的一些方法:
-
getName()
-
getAbsoluteFile()
-
getAbsolutePath()
-
getCanonicalFile()
-
getCanonicalPath()
-
getParentFile()
-
getParent()
此外,作为旁白建议,请考虑使用 JFileChooser
( Swing )而不是 FileDialog
(AWT),除非您正在开发旧版 GUI 应用程序。
关于java - java中如何通过文件名获取完整目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15315317/