Java 读取CSV文件并将每一行写入不同的文件

Java 读取CSV文件并将每一行写入不同的文件,java,Java,我的输入CSV有如下数据- VBS123ER,Abc_123,TEST_REPORT_FOR_SA,15-JUN-2020,76854,SAMPLE_REPORT VBS123ER,Abc_123,TEST_REPORT_FOR_SA,15-JUN-2020,76855,SAMPLE_REPORT 我想从我的CSV中读取每一行,并为每一行创建一个新的CSV/TXT文件。 类似-对于第1行,将创建一个名为1.txt/1.csv的文件,该文件将保存所有第1行数据。第2行也是如此

我的输入CSV有如下数据-

    VBS123ER,Abc_123,TEST_REPORT_FOR_SA,15-JUN-2020,76854,SAMPLE_REPORT


    VBS123ER,Abc_123,TEST_REPORT_FOR_SA,15-JUN-2020,76855,SAMPLE_REPORT
我想从我的CSV中读取每一行,并为每一行创建一个新的CSV/TXT文件。 类似-对于第1行,将创建一个名为1.txt/1.csv的文件,该文件将保存所有第1行数据。第2行也是如此,以此类推。。 在java中如何实现这一点

File f = new File("C:\\Test\\AR_POC\\Input.txt"); 
BufferedReader b = new BufferedReader(new FileReader(f)); 
String readLine = ""; 
System.out.println("Reading file using Buffered Reader"); 
while ((readLine = b.readLine()) != null) { 
    System.out.println(readLine); 
    for(int i = 0; i < readLine.length; i++) { 
        FileOutputStream fo = new FileOutputStream("C:\\Test\\AR_POC\\" + Name + i + ".txt"); 
        fo.write(readLine.getBytes()); 
        fo.close(); 
    } 
}
File f=新文件(“C:\\Test\\AR\u POC\\Input.txt”);
BufferedReader b=新的BufferedReader(新文件读取器(f));
字符串readLine=“”;
System.out.println(“使用缓冲读取器读取文件”);
而((readLine=b.readLine())!=null){
System.out.println(读线);
对于(inti=0;i
您应该计算输入文件中的行数,而不是当前行的长度:

File f = new File("C:\\Test\\AR_POC\\Input.txt"); 
BufferedReader b = new BufferedReader(new FileReader(f)); 
String readLine = ""; 
System.out.println("Reading file using Buffered Reader");
int i = 0;
while ((readLine = b.readLine()) != null) { 
    System.out.println(readLine);
    FileOutputStream fo = new FileOutputStream("C:\\Test\\AR_POC\\" + Name + i++ + ".txt"); 
    fo.write(readLine.getBytes()); 
    fo.close(); 
}

让我们知道您尝试了什么文件f=新文件(“C:\\Test\\AR\u POC\\Input.txt”);BufferedReader b=新的BufferedReader(新文件读取器(f));字符串readLine=“”;System.out.println(“使用缓冲读取器读取文件”);while((readLine=b.readLine())!=null){System.out.println(readLine);for(int i=0);将代码添加到问题中,并让我们知道您面临的问题。它将计算第一行的长度,并继续创建包含第一行数据的txt文件,直到长度。