chapter 10

2
Chapter 10: Using I/O 1. Because Java’s I/O system is quite large, containing many classes, interfaces, and method. Thus it is better to separate the two I/O Systems from each other. 2. Because using bytes streams “System.in” to read character from keyboard is more convenient that using character streams. 3. Open a file for reading bytes: try{ FileInputStream fin = new FileInputStream("fileName"); }catch(IOException exc){System.out.println("I/O Error" + exc);} 4. 5. Open a file for reading characters: try{ BufferedReader br = new BufferedReader(new FileReader("filename")); }catch(IOException exc){System.out.println("I/O Error" + exc);} 6. We can convert numeric string “123.23” in to binnar equivalent by using type wrapper Double. So, double d = Double.parseDouble(“123.23”); 7. CopyFileChangeSpaceToHyphen.java 8. CopyFileChangeSpaceToHyphen2.java 9. System.in is bytes tream

Upload: chetra-tep

Post on 28-Sep-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Chapter 10: Using I/O

1. Because Javas I/O system is quite large, containing many classes, interfaces, and method. Thus it is better to separate the two I/O Systems from each other.2. Because using bytes streams System.in to read character from keyboard is more convenient that using character streams.3. Open a file for reading bytes:try{FileInputStream fin = new FileInputStream("fileName");}catch(IOException exc){System.out.println("I/O Error" + exc);}4. 5. Open a file for reading characters:try{ BufferedReader br = new BufferedReader(new FileReader("filename"));}catch(IOException exc){System.out.println("I/O Error" + exc);}

6. We can convert numeric string 123.23 in to binnar equivalent by using type wrapper Double. So, double d = Double.parseDouble(123.23);7. CopyFileChangeSpaceToHyphen.java8. CopyFileChangeSpaceToHyphen2.java9. System.in is bytes tream10. It will return -1.11. DataInputStream12. Reader and Writer are at the top of the character stream.13. The try-with-resources statement is used for automatic closing a file.14. True.