久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

用字符串讀/寫二進(jìn)制文件?

Reading/writing a BINARY File with Strings?(用字符串讀/寫二進(jìn)制文件?)
本文介紹了用字符串讀/寫二進(jìn)制文件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

如何從二進(jìn)制文件中寫入/讀取字符串?

How can I write/read a string from a binary file?

我試過使用 writeUTF/readUTF (DataOutputStream/DataInputStream) 但太麻煩了.

I've tried using writeUTF / readUTF (DataOutputStream/DataInputStream) but it was too much of a hassle.

謝謝.

推薦答案

暫時忘記 FileWriter,DataOutputStream.

Forget about FileWriter, DataOutputStream for a moment.

  • 對于二進(jìn)制數(shù)據(jù),可以使用 OutputStreamInputStream 類.他們處理 byte[].
  • 對于文本數(shù)據(jù),使用 ReaderWriter 類.他們處理 String 可以存儲所有類型的文本,因為它在內(nèi)部使用 Unicode.
  • For binary data one uses OutputStream and InputStream classes. They handle byte[].
  • For text data one uses Reader and Writer classes. They handle String which can store all kind of text, as it internally uses Unicode.

文本到二進(jìn)制數(shù)據(jù)的交叉可以通過指定編碼來完成,默認(rèn)為OS編碼.

The crossover from text to binary data can be done by specifying the encoding, which defaults to the OS encoding.

  • new OutputStreamWriter(outputStream, encoding)
  • string.getBytes(編碼)

因此,如果您想避免 byte[] 并使用 String,則必須濫用以任何順序覆蓋所有 256 字節(jié)值的編碼.所以沒有UTF-8",但可能是windows-1252"(也稱為Cp1252").

So if you want to avoid byte[] and use String you must abuse an encoding which covers all 256 byte values in any order. So no "UTF-8", but maybe "windows-1252" (also named "Cp1252").

但內(nèi)部存在轉(zhuǎn)換,在極少數(shù)情況下可能會出現(xiàn)問題.例如 é 在 Unicode 中可以是一個代碼,也可以是兩個,e + 組合變音符號右重音 '.有一個轉(zhuǎn)換函數(shù)(java.text.Normalizer).

But internally there is a conversion, and in very rare cases problems might happen. For instance é can in Unicode be one code, or two, e + combining diacritical mark right-accent '. There exists a conversion function (java.text.Normalizer) for that.

這已經(jīng)導(dǎo)致問題的一種情況是不同操作系統(tǒng)中的文件名;MacOS 比 Windows 有另一個 Unicode 規(guī)范化,因此在版本控制系統(tǒng)中需要特別注意.

One case where this already led to problems is file names in different operating systems; MacOS has another Unicode normalisation than Windows, and hence in version control system need special attention.

所以原則上最好使用更繁瑣的字節(jié)數(shù)組,或ByteArrayInputStream,或java.nio 緩沖區(qū).還要注意 String char 是 16 位的.

So on principle it is better to use the more cumbersome byte arrays, or ByteArrayInputStream, or java.nio buffers. Mind also that String chars are 16 bit.

這篇關(guān)于用字符串讀/寫二進(jìn)制文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩 欧美 综合 | 欧美日本亚洲 | 久久伊人在 | 日韩精品一区二区三区中文在线 | 成人av在线播放 | 国产一区在线免费观看视频 | 国产精品视频网站 | 成人h动漫亚洲一区二区 | 精品伊人久久 | 国产一区www | 欧美性受 | 亚洲性视频网站 | 日韩精品在线网站 | 国产三级一区二区三区 | 午夜精品一区二区三区在线观看 | 天天操天天射天天 | 中文字幕乱码亚洲精品一区 | 一区二区三区福利视频 | 成年人视频在线免费观看 | 狠狠av | 亚洲黄色在线 | 剑来高清在线观看 | 日韩在线观看 | 国产精品久久久久久妇女6080 | 一级在线观看 | 成人av资源在线 | 九九热免费视频在线观看 | 国产精品一级 | 日韩一区中文字幕 | 精品综合久久 | 国产精品入口 | 日韩av啪啪网站大全免费观看 | 国产精品一区二区无线 | 国产一级在线 | 国产欧美在线观看 | 亚洲综合在线视频 | 国产精品久久久久久婷婷天堂 | 欧美 日韩 亚洲91麻豆精品 | 亚洲人在线播放 | 欧美中文字幕在线观看 | 亚洲精品乱码久久久久久按摩观 |