Lecture 21 - Extra - primitives o Eg Scanner inputStream =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Parsing Text Streams You can use the parseXXX() methods to convert strings to primitive types o Assumes one value per line o Eg: int i = Integer.parseInt(line.trim()); Can be done with the StreamTokenizer class o Returns tokens (items separated by white space or other separators) You can use the Scanner class to read from a text file o Methods like nextInt(), nextDouble(), etc allow you to read text and convert to
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: primitives o Eg: Scanner inputStream = new Scanner(new FileInputStream(“Test.txt”)); int n1 = inputStream.nextInt(); . . . Writing Binary Files • Can be done with DataOutputStream and FileOutputStream classes • Use writeXXX() methods on the DataOutputStream object o Eg: writeDouble(), writeInt(), etc Reading Binary Files • Can be done with DataInputStream and FileInputStream classes...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online