怎样用java编写程序获取已知文件的扩展名.能否给出能够直接运行的代码呢 20
1个回答
展开全部
import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
public class Test {
public static void main(String[] args) throws IOException {
File file = null;
JFileChooser chooser = new JFileChooser();
if (chooser.showDialog(null, "Please choose the file") == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
} else {
System.exit(0);
}
StringBuilder sb = new StringBuilder(file.getName()).reverse();
String ext = new StringBuilder(sb.substring(0, sb.indexOf("."))).reverse().toString();
System.out.println("文件扩展名为" + ext);
}
}
import java.io.IOException;
import javax.swing.JFileChooser;
public class Test {
public static void main(String[] args) throws IOException {
File file = null;
JFileChooser chooser = new JFileChooser();
if (chooser.showDialog(null, "Please choose the file") == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
} else {
System.exit(0);
}
StringBuilder sb = new StringBuilder(file.getName()).reverse();
String ext = new StringBuilder(sb.substring(0, sb.indexOf("."))).reverse().toString();
System.out.println("文件扩展名为" + ext);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询