Scanner objectScanner stdin = new Scanner(System.in);
System.in = an InputStream object predefined in java.lang
String inputLine = stdin.nextLine();
char c = inputLine.charAt(0); int i = Integer.parseInt(inputLine); long l = Long.parseLong(inputLine); float f = Float.parseFloat(inputLine); double d = Double.parseDouble(inputLine);
System.outSystem.out = a PrintStream object predefined in java.lang
print println
Strings, and any object
(override the
toString method to obtain desired format)Scanner objectFile srcFile = new File("myFile.txt");
Scanner fileIn = new Scanner(srcFile);FileNotFoundException (a checked exception)hasNext, hasNextInt, etc. next, nextInt, nextLine, etc. close
If the file has several pieces of information on each line, read one line at a time (using nextLine), then use the split method of the String class to divide the line into tokens (individual pieces of information) based on delimiters (the characters used to separate the pieces of information):
PrintStream objectFile dstFile = new File("myFile.txt");
PrintStream outFile = new PrintStream(dstFile);
new PrintStream(File file) new PrintStream(String fileName)
print println close
Strings, and any object
(override the
toString method to obtain desired format)