XLS读取
public List<String> getXlsFile(String fileName) throws IOException, BiffException{
List<String> result = new ArrayList();
File inputFile = new File(fileName);
FileInputStream fileInputStream = new FileInputStream(inputFile);
Workbook workbook = Workbook.getWorkbook(fileInputStream);
Sheet sheet = workbook.getSheet(0);
int rows = sheet.getRows();
for(int i =0;i<rows;i++) {
Cell cell = sheet.getCell(0, i);
result.add(cell.getContents());
}
return result;
}
TXT读取
public List<String> getTxtFile(String fileName) throws IOException {
InputStreamReader read = new InputStreamReader(new FileInputStream(fileName),"utf-8");
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt;
List<String> result = new ArrayList();
while((lineTxt = bufferedReader.readLine()) != null){
result.add(lineTxt);
}
return result;
}
csv的写入
public static void printCsv(String line,String outPutPath) throws IOException {
File outPutFile = new File(outPutPath);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(outPutFile), "utf-8");
outputStreamWriter.write(line + "\r\n");
outputStreamWriter.flush();
outputStreamWriter.close();
}