Sign in with
Sign up | Sign in
Your question
Solved

[JAVA] Help with I/O Streams

Last response: in Apps General Discussion
Share
May 19, 2012 7:46:04 AM

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?????

More about : java streams

May 19, 2012 7:49:15 AM

also CREATE , APPEND are flagged as errors. Dont know why.
m
0
l

Best solution

a b L Programming
May 21, 2012 12:58:36 PM

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?
Share
May 29, 2012 11:33:21 AM

Best answer selected by fasihxkhatib.
m
0
l
!