java - 如何从 JFileChooser 获取完整路径目录到字符串 Java
问题描述
所以我试图让我的程序选择一个带有 JFileChooser 的目录,然后使用该路径使用文件编写器创建一个文本文件,但我无法正确获取 JFileChooser 部分:(请帮助。
public class parcourire0test {
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO Auto-generated method stub
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("choosertitle");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
//这就是事情不起作用的地方
String Stringpath=Stringvalueof(chooser.getSelectedFile());
System.out.println("Stringpath: " + Stringpath);
} else {
System.out.println("No Selection ");
}
}
private static String Stringvalueof(File fi) {
// TODO Auto-generated method stub
return null;
}
}
但我得到 Stringpath : null
解决方案
推荐阅读
- php - 如何将图像添加到来自 Firebase 的 android 推送通知。使用离子 3 开发
- ios - 在 iOS 中混搭
- c# - 使用派生类型调用扩展方法的重载
- oauth-2.0 - Apache 晕厥与 OAuth 2
- javascript - 使用按钮的角度拖放元素
- android - 获取异常:java.net.SocketTimeoutException
- javascript - Sequelize 中的异步 getter/setter 作为属性的一部分
- c# - 在网络位置的程序中打开套接字时出错
- java - 主类完成后执行器线程继续运行
- java - Camunda 在启动期间在本地 oracle db 上引发错误