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日

你可能感兴趣的:(java- 文件交互)