Java输入输出流

最近遇到困难   我想把一个图片转化成二进制存入到记事本中    代码是这样的

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新手
  希望能给点注释 谢谢!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值