最近遇到困难 我想把一个图片转化成二进制存入到记事本中 代码是这样的
import java.io.*;
public class Upload {
public static void main(String args[]) {
int b,c;
byte tom[]=new byte[1000];
try{
File f=new File("d://blue.jpg");
InputStream in = new FileInputStream(f);
FileOutputStream out = new FileOutputStream("d://line.txt");
while((b=in.read(tom,0,100))!=-1){
in.read(tom,0,1000);
out.write(tom);
}
in.close();
out.close();
}catch(IOException e){
System.out.print("file read err"+e);
}
}
}
我又写了一段 读取 该文件的代码,我想实现从记事本里面 将它二进制流读出来 然后再显示出来
代码是这样的
import java.io.*;
public class show {
public static void main(String args[]) {
int b,c;
byte tom[]=new byte[1000];
try{
File f=new File("d://line.txt");
FileInputStream in = new FileInputStream(f);
FileOutputStream out = new FileOutputStream("d://line.jpg");
while((b=in.read(tom,0,100))!=-1){
in.read(tom,0,1000);
out.write(tom);
}
in.close();
out.close();
}catch(IOException e){
System.out.print("file read err"+e);
}
}
}
当我 运行完这两段代码后
就去打开line.jpg
但是 什么都没有
这是怎么回事呢??
希望大家能帮助我一下
我是java新手
希望能给点注释 谢谢!!!