[JAVA] Help with I/O Streams

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(;

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

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

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.

3 answers Last reply Best Answer
More about java streams
  1. also CREATE , APPEND are flagged as errors. Dont know why.
  2. Best answer
    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?
  3. Best answer selected by fasihxkhatib.
Ask a new question

Read More

Programming Java Consoles Apps