[英]Java Serialization : How use Object InputStream / Object Output Stream
i'm learning Java language thanks "to Deitel & Deitel How To Program in Java 10ed". 感谢“ Deitel&Deitel如何在Java 10ed中编程”,我正在学习Java语言。 But i have some problem about understanding the stream of object in file . 但是我对理解文件中的对象流有一些问题。 I understand that ObjectOutputStream
enables you to write Object in file. 我知道ObjectOutputStream
使您可以在文件中写入Object。 Using Book's words : ObjectOutputStream
is initialized with a Stream Object , because it writes byte in the file. 用Book的话说: ObjectOutputStream
用Stream Object初始化,因为它在文件中写入了字节。 Instead ObjectInputStream
enable you to read Object in the file . 相反, ObjectInputStream
使您可以读取文件中的Object。 And ObjectInputStream is initialized with aa Stream Object for catch bytes from file. 然后使用流对象初始化ObjectInputStream来捕获文件中的字节。 But what is a Stream object ? 但是什么是Stream对象? 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
? 什么是Files.newOutputStream
? What Does it return ? 它返回什么?
Thanks for Attention (if you tell me books for learning java better than mine it's very good!) 感谢您的关注(如果您告诉我比我的书更好地学习Java的书,那就太好了!)
(i'm italian, so maybe my english would be not so good ) (我是意大利人,所以也许我的英语不太好)
Files.newOutputStream
创建一个OutputStream对象,使您可以在newOutputStream(Path path, OpenOption... options)
path
参数所表示的Path
上写入File
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.