首页 > 其他 > 详细

磁盘文件读取

时间:2015-05-14 18:25:55      阅读:116      评论:0      收藏:0      [点我收藏+]

1、按字符读取

 public String redConfigMSG() {
        String configMSG = "";
        String path = "C:\\PrinterConfig\\BarCodePrinterConfig.txt";
        try {
            int i;
            FileInputStream fis = new FileInputStream(path);
            while ((i = fis.read()) != -1) {
                configMSG += (char) i;
            }
        } catch (FileNotFoundException e) {
            System.out.println(e);
        } catch (IOException e) {
            System.out.println(e);
        }
        return configMSG;
    }

2、按字符读取(一次读取一行)

  public static void main(String[] args) {     
        File file = new File("C:\\PrinterConfig\\BarCodePrinter.txt");     
        try {     
            FileReader fileReader = new FileReader(file);     
            BufferedReader bufferedReader = new BufferedReader(fileReader);     
            String str = bufferedReader.readLine();     
            while (str != null) {
                System.out.println("line:"+str);
                str = bufferedReader.readLine();     
            }     
        } catch (FileNotFoundException e) {    
            //当抛出多个异常时,子异常当在父异常前抛出。   
            e.printStackTrace();     
        } catch (IOException e) {     
            e.printStackTrace();     
        }     
    }   

 

磁盘文件读取

原文:http://www.cnblogs.com/XueRong-7/p/4503851.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!