标签:output opened fileread com close user new txt exce
package com.gdin.dome; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import org.junit.Test; public class dome5 { @Test public void fun(){ try { /* * 用行为读取的方式,没读取到一行数据就转化为数值 */ File file = new File("C:/Users/Administrator/Desktop/test.txt"); BufferedReader reader = new BufferedReader(new FileReader(file)); FileOutputStream output = new FileOutputStream(new File("C:/Users/Administrator/Desktop/a.jpg")); int i = 0; String s = null;//用于保存读取的 字符 long line = 1l;//每次读取1行 byte[] b= new byte[1024]; while((s = reader.readLine())!= null){ if(line==1){ s = "ff"; } i = Integer.parseInt(s, 16); output.write(i); line++; } reader.close(); output.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
package com.gdin.dome;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import org.junit.Test;
public class dome5 {
@Test
public void fun(){
try {
/*
* 用行为读取的方式,没读取到一行数据就转化为数值
*/
File file = new File("C:/Users/Administrator/Desktop/test.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
FileOutputStream output = new FileOutputStream(new File("C:/Users/Administrator/Desktop/a.jpg"));
int i = 0;
String s = null;//用于保存读取的 字符
long line = 1l;//每次读取1行
byte[] b= new byte[1024];
while((s = reader.readLine())!= null){
if(line==1){
s = "ff";
}
i = Integer.parseInt(s, 16);
output.write(i);
line++;
}
reader.close();
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
从一个txt文件中读取内容,每一行只有一个16进制的编码。但是出现问题就是第一行为不可识别,于是干脆给一行赋值,然后通过输出流输出文件
标签:output opened fileread com close user new txt exce
原文地址:http://www.cnblogs.com/jiang-z/p/Java.html