1. 程式人生 > >java讀取檔案

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();                 }             }         }