Java Input/Output
6 May 2019 OSU CSE 1
Java Input/Output 6 May 2019 OSU CSE 1 Overview The Java I/O - - PowerPoint PPT Presentation
Java Input/Output 6 May 2019 OSU CSE 1 Overview The Java I/O (Input/Output) package java.io contains a group of interfaces and classes similar to the OSU CSE components SimpleReader and SimpleWriter component families Except that
6 May 2019 OSU CSE 1
6 May 2019 OSU CSE 2
6 May 2019 OSU CSE 3
6 May 2019 OSU CSE 4
6 May 2019 OSU CSE 5
6 May 2019 OSU CSE 6
6 May 2019 OSU CSE 7
6 May 2019 OSU CSE 8
public static void main(String[] args) { SimpleReader input = new SimpleReader1L(); String s = input.nextLine(); ... input.close(); }
6 May 2019 OSU CSE 9
public static void main(String[] args) { SimpleReader input = new SimpleReader1L(); String s = input.nextLine(); ... input.close(); }
6 May 2019 OSU CSE 10
6 May 2019 OSU CSE 11
InputStream- Reader Readable Reader Closeable FileReader BufferedReader
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 12
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 13
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 14
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 15
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 16
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 17
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 18
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 19
6 May 2019 OSU CSE 20
public static void main(String[] args) { Scanner input = new Scanner(System.in); String s = input.nextLine(); ... input.close(); }
6 May 2019 OSU CSE 21
public static void main(String[] args) { Scanner input = new Scanner(System.in); String s = input.nextLine(); ... input.close(); }
6 May 2019 OSU CSE 22
public static void main(String[] args) { Scanner input = new Scanner(System.in); String s = input.nextLine(); ... input.close(); }
6 May 2019 OSU CSE 23
public static void main(String[] args) { Scanner input = new Scanner(System.in); String s = input.nextLine(); ... input.close(); }
6 May 2019 OSU CSE 24
public static void main(String[] args) { SimpleReader input = new SimpleReader1L(); while (!input.atEOS()) { s = input.nextLine(); ... } ... input.close(); }
6 May 2019 OSU CSE 25
public static void main(String[] args) { SimpleReader input = new SimpleReader1L(); while (!input.atEOS()) { s = input.nextLine(); ... } ... input.close(); }
6 May 2019 OSU CSE 26
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); while (s != null) { ... s = input.readLine(); } ... input.close(); }
6 May 2019 OSU CSE 27
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); while (s != null) { ... s = input.readLine(); } ... input.close(); }
6 May 2019 OSU CSE 28
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String s = input.readLine(); while (s != null) { ... s = input.readLine(); } ... input.close(); }
6 May 2019 OSU CSE 29
public static void main(String[] args) { SimpleReader input = new SimpleReader1L("data/test.txt"); String s = input.nextLine(); ... input.close(); }
6 May 2019 OSU CSE 30
public static void main(String[] args) { SimpleReader input = new SimpleReader1L("data/test.txt"); String s = input.nextLine(); ... input.close(); }
6 May 2019 OSU CSE 31
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new FileReader("data/test.txt")); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 32
public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader( new FileReader("data/test.txt")); String s = input.readLine(); ... input.close(); }
6 May 2019 OSU CSE 33
6 May 2019 OSU CSE 34
public static void main(String[] args) { SimpleWriter output = new SimpleWriter1L();
...
}
6 May 2019 OSU CSE 35
public static void main(String[] args) { SimpleWriter output = new SimpleWriter1L();
...
}
6 May 2019 OSU CSE 36
6 May 2019 OSU CSE 37
OutputStream- Writer Flushable Writer Closeable FileWriter BufferedWriter Appendabl e PrintWriter
public static void main(String[] args) { ... System.out.print("foo"); System.out.println(" and bar"); ... }
6 May 2019 OSU CSE 38
public static void main(String[] args) { ... System.out.print("foo"); System.out.println(" and bar"); ... }
6 May 2019 OSU CSE 39
public static void main(String[] args) { ... System.out.print("foo"); System.out.println(" and bar"); ... }
6 May 2019 OSU CSE 40
public static void main(String[] args) { SimpleWriter output = new SimpleWriter1L("data/test.txt");
...
}
6 May 2019 OSU CSE 41
public static void main(String[] args) { SimpleWriter output = new SimpleWriter1L("data/test.txt");
...
}
6 May 2019 OSU CSE 42
public static void main(String[] args) throws IOException { PrintWriter output = new PrintWriter( new BufferedWriter ( new FileWriter("data/test.txt")));
...
}
6 May 2019 OSU CSE 43
public static void main(String[] args) throws IOException { PrintWriter output = new PrintWriter( new BufferedWriter ( new FileWriter("data/test.txt")));
...
}
6 May 2019 OSU CSE 44
6 May 2019 OSU CSE 45
6 May 2019 OSU CSE 46
6 May 2019 OSU CSE 47
6 May 2019 OSU CSE 48
public static void main(String[] args) { // Code to open file // Code to read from file // Code to close file }
6 May 2019 OSU CSE 49
public static void main(String[] args) { BufferedReader input; try { input = new BufferedReader( new FileReader("data/test.txt")); } catch (IOException e) { System.err.println("Error opening file"); return; } // Code to read from file // Code to close file }
6 May 2019 OSU CSE 50
public static void main(String[] args) { BufferedReader input; try { input = new BufferedReader( new FileReader("data/test.txt")); } catch (IOException e) { System.err.println("Error opening file"); return; } // Code to read from file // Code to close file }
6 May 2019 OSU CSE 51
public static void main(String[] args) { BufferedReader input; try { input = new BufferedReader( new FileReader("data/test.txt")); } catch (IOException e) { System.err.println("Error opening file"); return; } // Code to read from file // Code to close file }
6 May 2019 OSU CSE 52
public static void main(String[] args) { BufferedReader input; try { input = new BufferedReader( new FileReader("data/test.txt")); } catch (IOException e) { System.err.println("Error opening file"); return; } // Code to read from file // Code to close file }
6 May 2019 OSU CSE 53
public static void main(String[] args) { BufferedReader input; try { input = new BufferedReader( new FileReader("data/test.txt")); } catch (IOException e) { System.err.println("Error opening file"); return; } // Code to read from file // Code to close file }
6 May 2019 OSU CSE 54
public static void main(String[] args) { BufferedReader input; try { input = new BufferedReader( new FileReader("data/test.txt")); } catch (IOException e) { System.err.println("Error opening file"); return; } // Code to read from file // Code to close file }
6 May 2019 OSU CSE 55
public static void main(String[] args) { BufferedReader input; try { input = new BufferedReader( new FileReader("data/test.txt")); } catch (IOException e) { System.err.println("Error opening file"); return; } // Code to read from file // Code to close file }
6 May 2019 OSU CSE 56
public static void main(String[] args) { BufferedReader input; try { input = new BufferedReader( new FileReader("data/test.txt")); } catch (IOException e) { System.err.println("Error opening file"); return; } // Code to read from file // Code to close file }
6 May 2019 OSU CSE 57
public static void main(String[] args) { // Code to open file try { String s = input.readLine(); while (s != null) { ... s = input.readLine(); } } catch (IOException e) { System.err.println("Error reading from file"); } // Code to close file }
6 May 2019 OSU CSE 58
public static void main(String[] args) { // Code to open file try { String s = input.readLine(); while (s != null) { ... s = input.readLine(); } } catch (IOException e) { System.err.println("Error reading from file"); } // Code to close file }
6 May 2019 OSU CSE 59
public static void main(String[] args) { // Code to open file try { String s = input.readLine(); while (s != null) { ... s = input.readLine(); } } catch (IOException e) { System.err.println("Error reading from file"); } // Code to close file }
6 May 2019 OSU CSE 60
public static void main(String[] args) { // Code to open file // Code to read from file try { input.close(); } catch (IOException e) { System.err.println("Error closing file"); } }
6 May 2019 OSU CSE 61
public static void main(String[] args) { // Code to open file // Code to read from file try { input.close(); } catch (IOException e) { System.err.println("Error closing file"); } }
6 May 2019 OSU CSE 62
6 May 2019 OSU CSE 63
6 May 2019 OSU CSE 64
6 May 2019 OSU CSE 65
6 May 2019 OSU CSE 66
6 May 2019 OSU CSE 67
6 May 2019 OSU CSE 68
– http://docs.oracle.com/javase/tutorial/essential/io/index.html
6 May 2019 OSU CSE 69