[英]How to restrict raw data to save in text file
我正在 Java 中開發一個小型應用程序。 At certain point i need to save the object of my custom class to a text file for this i override toString()
method in my custom class and then use ObjectOutputStream
class to save object of my custom class to text file. 現在一切正常,即我的文本文件包含文本,但與該文本一起它還包含一些奇怪的字符或原始數據。 以下三行包含主要代碼
ObjectOutputStream outputStream = null;
outputStream = new ObjectOutputStream(new FileOutputStream(filename));
outputStream.writeObject(person);//person is the instance of my custom class
有沒有辦法限制將原始數據保存在我的文本文件中?
ObjectOutputStream 序列化傳遞給 writeObject() 的對象。 它不寫 object 的文本版本。 如果要將toString()返回的值寫入文件,則用FileWriter之類的東西打開一個文件,調用toString()方法獲取String,然后寫入FileWriter。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.