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个文件 –