Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The solution of objectoutputstream garbled code

Shulou Source: shulou.com Published: 2022-06-02 09:11:27 10月13日 Update

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!

Tags: Garbled article method problem output character string different code value interest content at the same time platform sequence file scheme method more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Xiaomi Redmi Microsoft Huawei