JAVA的IO包如何读写图片文件?
最好能告诉我个实例,谢谢!
如果我下面写的错的不是特离谱,帮我改一下更好,谢谢!!
我这写完了全是乱码..
********************************************************************
import java.io.*;
class IOTest
{
public static void main(String[] args) throws IOException
{
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("1.jpg")));
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("2.jpg")));
int i =in.read();
while(i!=-1)
{
i =in.read();
out.write(i);
}
out.flush();
in.close();
out.close();
}
}
----------------解决方案--------------------------------------------------------
import java.io.*;
class IOTest{
public static void main(String[] args) throws IOException{
DataInputStream din = new DataInputStream(new BufferedInputStream(new FileInputStream("1.jpg")));
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("2.jpg")));
int i=din.available();
byte[] b=new byte[i];
din.readFully(b);
out.write(b);
out.flush();
din.close();
out.close();
}
}
----------------解决方案--------------------------------------------------------
你少写一个东西,是专门读写读书的文件流通
----------------解决方案--------------------------------------------------------
谢谢!可以解决了.
----------------解决方案--------------------------------------------------------