利用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”
分割。