我讀的文本數據[UTF-8格式]文件,並將其存儲在一個字符串,該字符串轉換爲十六進制格式,這十六進制字符串保存到另一個文件,但我要救這個轉換的十六進制字符串逐行。怎麼做?寫入文件一行一行
String sCurrentLine;
br = new BufferedReader(new FileReader("demmo123.txt"));
while ((sCurrentLine = br.readLine()) != null) {
sb1.append(sCurrentLine);
}
String ss = sb1.toString();
Scanner sc = new Scanner(ss);
String helloWorldHex = toHexString(ss.getBytes());
file = new File("demmo.txt");
fop = new FileOutputStream(file);
if (!file.exists()) {
file.createNewFile();
}
byte[] contentInBytes = helloWorldHex.getBytes();
fop.write(helloWorldHex.getBytes());
fop.write(contentInBytes);
fop.flush();
fop.close();
fop.write(helloWorldHex.getBytes());
顯示你到目前爲止的代碼。 – PeterMmm
String sCurrentLine; br = new BufferedReader(new FileReader(「demmo123.txt」)); 而(!(sCurrentLine = br.readLine())= NULL){ \t sb1.append(sCurrentLine); \t} \t字符串SS = sb1.toString(); \t Scanner sc = new Scanner(ss); \t String helloWorldHex = toHexString(ss.getBytes()); \t file = new File(「demmo.txt」); \t fop = new FileOutputStream(file); \t如果(!file.exists()){ \t file.createNewFile(); \t} \t字節[] contentInBytes = helloWorldHex.getBytes(); fop.write(helloWorldHex.getBytes()); \t \t \t //fop.write(contentInBytes); \t \t \t fop.flush(); \t \t \t fop.close(); \t \t \t \t \t \t \t \t \t fop.write(helloWorldHex.getBytes()); – user3134139
@ user3134139:請將您的代碼添加到您的問題中。使用'編輯'鏈接。 – PakkuDon