六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 57|回复: 0

按行读取文件

[复制链接]

升级  4%

16

主题

16

主题

16

主题

秀才

Rank: 2

积分
56
 楼主| 发表于 2013-2-4 22:29:58 | 显示全部楼层 |阅读模式
package bb;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.InputStreamReader;/** * 按行读取文件 * @author xiyin1979 */public class bb {public static void main(String[] args) throws Exception {File file=new File("D:\\workspace\\Util\\src\\bb\\aa.xml");BufferedReader br =  new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));String oneLine = "";while((oneLine=br.readLine())!=null){System.out.println(oneLine);}}}

using System;using System.Collections.Generic;using System.Text;using System.IO;namespace IOStream{    class Start    {        public static void Main()        {            try            {                string path = @"D:\workspace\Util\src\bb\aa.xml";                FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);                StreamReader reader = new StreamReader(fs);                string line = String.Empty;                while ((line = reader.ReadLine()) != null)                {                    Console.WriteLine(line);                }                                Console.ReadLine();            }            catch (Exception e)            {                Console.WriteLine(e.ToString());                Console.WriteLine(e.Message);                Console.ReadLine();            }        }    }}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表