fos1.txt文件中的結果輸出是d,但是我希望它在文件中是100,我該怎麼做?將ByteArrayOutputStream的輸出顯示爲整數
public class Byteo {
public static void main(String[] args) {
try {
FileOutputStream fos1 = new FileOutputStream("G:\\fos1.txt");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int x = 100;
bos.write(x);
try {
bos.writeTo(fos1);
bos.flush();
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
你可以讓x字符串? –
沒有工作。在我的問題中要清楚的是輸出是ASCII格式,我希望它是原始格式。 – Hassan
你確定嗎?如果你使用'bos.write(Integer.toString(x).getBytes())'這樣的指令;'你應該有100個文件 –