小编Phi*_*hil的帖子

如何检查文件是否为excel文件?

我正在编写一个程序,必须选择一个excel文件,该文件将由程序读取.我现在的问题是,如果文件是excel文件,怎么能证明?

在此方法中选择该文件:

JButton btnFile = new JButton("Select Excel File");
btnFile.setPreferredSize(new Dimension(40, 40));
btnFile.addActionListener(new ActionListener() {
    // Handle open button action.
    public void actionPerformed(ActionEvent e) {
        final JFileChooser fc = new JFileChooser();
        int returnVal = fc.showOpenDialog(frame);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            file = fc.getSelectedFile();
            // This is where a real application would open the file.
            System.out.println("File: " + file.getName() + ".");
        } else {
            System.out.println("Open command cancelled by user.");
        }
        System.out.println(returnVal);
    }
});
Run Code Online (Sandbox Code Playgroud)

java validation excel

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

excel ×1

java ×1

validation ×1