java- 文件交互

用户选取文件对话框

    /**
     * Lets the user select an input file using a standard file selection dialog
     * box. If the user cancels the dialog without selecting a file, the return
     * value is null.
     */
    private File getInputFileNameFromUser() {
        JFileChooser fileDialog = new JFileChooser();
        fileDialog.setDialogTitle("Select File for Input");
        int option = fileDialog.showOpenDialog(null);
        if (option != JFileChooser.APPROVE_OPTION)
            return null;
        else
            return fileDialog.getSelectedFile();
    }

scanner

  1. next()
    • Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern. This method may block while waiting for input to scan, even if a previous invocation of hasNext()returned true.
  • 结束符为空格。
  1. nextline()
    • Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator (enter key) at the end. The position is set to the beginning of the next line.
      Since this method continues to search through the input looking for a line separator, it may buffer all of the input searching for the line to skip if no line separators are present.
    • 结束符为enter。

@参考文献

作者 @FL
2019 年 04月 24日

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容