首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java 按行读取资料内容

2012-10-27 
java 按行读取文件内容String readPath ??String writePath ????BufferedReader in null??Bu

java 按行读取文件内容

String readPath = "";
??String writePath = "";
??
??BufferedReader in = null;
??BufferedWriter os = null;
??
??try {
???// 读取文件(readPaht)内容
???if(null != in){
????in.close();
???}
???in = new BufferedReader(new InputStreamReader(new FileInputStream(readPath)));
???//
???if(null != os){
????os.close();
???}
???os = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writePath)));
???String line = in.readLine();

???while (null != line && !"".equals(line)) {
????os.write(line);
????os.newLine();
????line = in.readLine();
???}

??} catch (Exception e) {
???e.printStackTrace();
??} finally {
???try{
????if(null != in){
?????in.close();
????}
????if(null != os){
?????os.close();
????}
???}catch (Exception e) {
????e.printStackTrace();
???}
??}

热点排行