为什么用字节流读取写入文件会造成文件大小不一致?
我的程序代码如下:
import java.io.*;
public class IOTest{
public static void main(String[] args){
try{
DataInputStream in2 = new DataInputStream(new BufferedInputStream(new FileInputStream("1.jpg")));
DataOutputStream out2= new DataOutputStream(new BufferedOutputStream(new FileOutputStream("2.jpg")));
while( in2.available()!=0)
out2.writeByte(in2.readByte());
}
catch(IOException e){}
}
}
我的想法是:从文件1.jpg产生一个DataInputStream,然后从此stream中读取数据写入2.jpg,结果2.jpg文件和1.jpg文件大小不致了,请问这是什么?
import java.io.*;
public class IOTest{
public static void main(String[] args){
try{
DataInputStream in2 = new DataInputStream(new BufferedInputStream(new FileInputStream("1.jpg")));
DataOutputStream out2= new DataOutputStream(new BufferedOutputStream(new FileOutputStream("2.jpg")));
while( in2.available()!=0)
out2.writeByte(in2.readByte());
}
catch(IOException e){}
}
}
我的想法是:从文件1.jpg产生一个DataInputStream,然后从此stream中读取数据写入2.jpg,结果2.jpg文件和1.jpg文件大小不致了,请问这是什么?
...全文
相关推荐
使用字节流方式操作文件,读取和写入文件
使用字节流方式操作文件,读取和写入文件,关闭文件
Java字节流数据逐行读取(readLine)
Java字节流数据逐行读取(readLine)
c++读取写入txt文件
读取写入txt文件,一个小小的程序,用c++读取txt文件
python 读取、写入txt文件的示例
写入文件 使用open()函数和write()函数 但是有两种写法,分别是’a’和’w’ ‘a’ 表示写入文件 若无该文件会直接创建一个 如果存在这个文件,会接着已有的内容的后面写入 with open('D:\\test.txt','a',encoding='utf-8') as f: text = '\n奔涌吧,后浪' f.write(text) 程序运行前: 程序运行后: ‘w’ 表示写入文件 若无该文件会直接创建一个 如果存在这个文件,里面的内容会被后面写入的内容替换掉 with open('D:\\test.txt','w',encoding='utf-8') as
Javascript写入和读取txt文件
在html中通过Javascript实现对txt文件的写入和读取txt文件


Java SE
