读文件输出数字码串

来源:互联网 发布:mac sftp 客户端 编辑:程序博客网 时间:2024/05/22 12:11

package TestIO;
import java.io.*;
public class Test1 {
 public static void main(String[] args) {
      StringBuffer sb = new StringBuffer();
   File fin = new File("D:\\picmanage\\2017\\02\\thumb\\b5c6b1158d5445efa429575b5be927c1_big.jpg");
   FileInputStream fis = null;
   try{
    //读文件字节流
    fis = new FileInputStream(fin);
    byte[] buffer = new byte[fis.available()];//定义存储数组
    fis.read(buffer);
    StringBuffer str = new StringBuffer();
    for (byte b : buffer) {
     str.append(b+" ");
    }
    sb.append(str.toString().substring(0, str.toString().length()-1) + ";");
   }catch(IOException e1){
    e1.printStackTrace();
   }catch(Exception e2){
    e2.printStackTrace();
   } finally {
    //关闭读文件字节流
    try {
     if (null != fis) fis.close();
    } catch (Exception e) {
    }
   }
   System.out.println(sb.toString());
 }
}
0 0
原创粉丝点击