Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution of objectoutputstream garbled code

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the objectoutputstream garbled solution, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

The solution to objectoutputstream garbled: first find the part of the code that appears garbled; then use "new PrintStream (" new FileOutputStream ("c:\\ cc.txt")); "write the string.

This article operating environment: windows7 system, Dell G3 computer.

How to solve the objectoutputstream garbled problem?

Record the problem of garbled ObjectOutputStream output

Issue:

FileOutputStream file = new FileOutputStream ("D:/test.txt"); ObjectOutputStream output = new ObjectOutputStream (file); output.writeObject ("test01\ r\ n"); output.writeObject ("test02\ r\ n"); output.close (); file.close ()

The output is as follows:

 roomt test01t test02

Solution

What writeObject writes to the file is the serialized content of the String class, which, of course, cannot be viewed correctly. It is better to use PrintStream to write strings. And outputting "\ n" and "\ r\ n" is not a good method, because different platform carriage returns are different. The following line breaks are used to solve cross-platform problems:

PrintStream file = new PrintStream (new FileOutputStream ("c:\\ cc.txt"); file.println ("test01"); file.println ("test02"); Thank you for reading this article carefully. I hope the article "the solution to objectoutputstream garbled" shared by the editor will be helpful to you. At the same time, I also hope you will support us, pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report