0

i'm learning Java language thanks "to Deitel & Deitel How To Program in Java 10ed". But i have some problem about understanding the stream of object in file . I understand that ObjectOutputStream enables you to write Object in file. Using Book's words : ObjectOutputStream is initialized with a Stream Object , because it writes byte in the file. Instead ObjectInputStream enable you to read Object in the file . And ObjectInputStream is initialized with a a Stream Object for catch bytes from file. But what is a Stream object ? This is the code to Output:

output = new ObjectOutputStream(Files.newOutputStream( Paths.get("clients.ser")));

this is the code to input:

input = new ObjectInputStream(Files.newInputStream(Paths.get("clients.ser"));

What is Files.newOutputStream? What Does it return ?

Thanks for Attention (if you tell me books for learning java better than mine it's very good!)

(i'm italian, so maybe my english would be not so good )

1

2 Answers 2

1

This method opens or creates a file and return an output stream that may be used to write bytes to the file. This returned stream is threadsafe.

For detailed description please visit: Java Doc

Sign up to request clarification or add additional context in comments.

2 Comments

Is correct think that say "return an output stream" is like say "return a reference to file" ? Maybe my problem is that i started to program in C so it easier for me think to a a FILE pointer
Yes you are right, it will return a reference to file.
0

Files.newOutputStream creates an OutputStream object enabling you to write to a File on the Path denoted by path argument of newOutputStream(Path path, OpenOption... options).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.