[JAVA] Help with I/O Streams

fasihxkhatib

Distinguished
Aug 25, 2011
74
0
18,580
0
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?????
 

Rusting In Peace

Distinguished
Jul 2, 2009
313
0
19,060
34
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
313
0
19,060
34
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?
 
Thread starter Similar threads Forum Replies Date
rcromwell92 Apps General Discussion 1
Marshall Honorof Apps General Discussion 1
A Apps General Discussion 2
G Apps General Discussion 2
G Apps General Discussion 0
G Apps General Discussion 0
henrytcasey Apps General Discussion 3
henrytcasey Apps General Discussion 8
henrytcasey Apps General Discussion 4
G Apps General Discussion 0
M Apps General Discussion 8
Y Apps General Discussion 1
G Apps General Discussion 0
G Apps General Discussion 1
G Apps General Discussion 1
G Apps General Discussion 0
A Apps General Discussion 1
A Apps General Discussion 1
henrytcasey Apps General Discussion 3
henrytcasey Apps General Discussion 2

ASK THE COMMUNITY