[JAVA] Help with I/O Streams

fasihxkhatib

Distinguished
Aug 25, 2011
74
0
18,580
Im currently on the topic of IO Streams to write and read data from/to file and console & I need help to remember the syntax.

while creating a StreamTokenizer object I created it as...
StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

while writing data to the file The syntax was
BufferedOutputStream fileOut = new BufferedOutputStream(Files.newOutputStream(file)

AND
BufferedWriter fileOut = Files.newBufferedWriter(file,Charset.forName("UTF-16"),CREATE,APPEND)

MY QUESTION IS.......
All these IO operations use streams but in the first case StreamTokenizer was created using ALL CONSTRUCTORS of the encapsulated classes
but in the other two
a constructor was used along with a Files static method.


ANY MNEMONIC TO REMEMBER THIS?????
 
Solution
Err you can create a BufferedWriter with the new keyword too you don't have to use the Files static method. I think the Files class is new to Java 1.7. I'd personally construct writer objects in the regular way to maintain backwards compatibility.

Create and append aren't declared in your enclosing class. Perhaps you are trying to refer to statics from another class?

Rusting In Peace

Distinguished
Jul 2, 2009
312
0
19,060
Err you can create a BufferedWriter with the new keyword too you don't have to use the Files static method. I think the Files class is new to Java 1.7. I'd personally construct writer objects in the regular way to maintain backwards compatibility.

Create and append aren't declared in your enclosing class. Perhaps you are trying to refer to statics from another class?
 
Solution