CSVfileUtil 格式化csv文件

利用java實現對.csv文件的格式化


public static String readLine(String path,String fileName){
            CSVUtil.fileInfo=path+"\\"+fileName;
            String result="";
            File file = new File(fileInfo);
            if (!file.exists() || !file.isFile()) {
                System.out.println("there is no such file :" + fileInfo);
                result=null;
            }
            else {
                try {
                fls = new FileInputStream(file);
                isr = new InputStreamReader(fls, "utf-8");
                br = new BufferedReader(isr);
                String temp=br.readLine();
                while(temp!=null){
                    result=result+temp+"\n";
                    temp=br.readLine();
                }
            }catch(FileNotFoundException e){
                e.printStackTrace();
            }catch(UnsupportedEncodingException e){
                e.printStackTrace();
            }catch(IOException e){
                e.printStackTrace();
            }
        }
        return result;
    }

    public static void closeALL(){
        try {
            br.close();
            fls.close();
            isr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

其中CSVfileUtil是自己要新建的類。這段代碼是輸出所有的.csv文件的內容。每行用“\n”分割。

發佈了34 篇原創文章 · 獲贊 30 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章