ReadFileUsingJFileChooser
来源:互联网 发布:景安网络备案幕布 编辑:程序博客网 时间:2024/05/21 14:28
package java_test;
import javax.swing.JFileChooser;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ReadFileUsingJFileChooser {
public static void main(String[] args) throws FileNotFoundException {
JFileChooser fileChooser = new JFileChooser();
if(fileChooser.showOpenDialog(null) ==
JFileChooser.APPROVE_OPTION) {
// Get the selected file
java.io.File file = fileChooser.getSelectedFile();
// Create a Scanner for the file
Scanner input = new Scanner(file);
// Read text from the file
while(input.hasNext())
System.out.println(input.nextLine());
// Close the file
input.close();
}
else
System.out.println("NO file selected");
}
}
0 0