| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package com.uas.eis.serviceImpl;
- import java.io.*;
- /**
- * @author: zhouy
- * @date: 2021/11/26 16:10
- * @desc:
- */
- public class Test {
- public static void main(String[] args) throws Exception {
- InputStream is=new FileInputStream("C:\\Picture\\a.txt");
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- String str = null;
- StringBuilder sb = new StringBuilder();
- while ((str = br.readLine()) != null) {
- System.out.println(str);
- sb.append(str);
- }
- saveToImgFile(sb.toString().toUpperCase(),"C:\\Picture\\p7.jpg");
- /* DataOutputStream sos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("C:\\\\Picture\\\\p5.jpg")));
- InputStream in = new FileInputStream("C:\\Picture\\a.txt");
- int len = 0;
- byte[] b = new byte[1024];
- while ((len = in.read(b)) != -1) {
- System.out.println("write");
- sos.write(b,0,len);
- }
- sos.close();
- in.close();*/
- }
- public static void saveToImgFile(String src,String output){
- if(src==null||src.length()==0){
- return;
- }
- try{
- FileOutputStream out = new FileOutputStream(new File(output));
- byte[] bytes = src.getBytes();
- for(int i=0;i<bytes.length;i+=2){
- out.write(charToInt(bytes[i])*16+charToInt(bytes[i+1]));
- }
- out.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- private static int charToInt(byte ch){
- int val = 0;
- if(ch>=0x30&&ch<=0x39){
- val=ch-0x30;
- }else if(ch>=0x41&&ch<=0x46){
- val=ch-0x41+10;
- }
- return val;
- }
- }
|