java讀取文件

        //獲取文件內容
        Date date=new Date();
        String time=DateUtil.datetoString(date, "yyyyMMdd");//此處用的自己的工具類
        String filename="/home/infra/StaffSyc/"+"USERINFOSYN_+"time"+".TXT";
        File file=new File(filename);
        if(!file.exists()){
            throw new BusiException("文件不存在");
        }
        if(file.length()==0){
            throw new BusiException("文件不能爲空");
        }
        BufferedReader bre=null;
        String str="";
        List<String> list=new ArrayList<String>();
        try{
            bre=new BufferedReader(new InputStreamReader(new FileInputStream(filename),"gbk"));
            while((str=bre.readLine())!=null){
                list.add(str);
            }
        }catch(IOException e){
            e.printStackTrace();  
        }finally{
            if(bre != null){
                try {
                    bre.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章