我需要在Java中读取3个CSV文件. 所以这一部分我已经做到了,但我想为下一部分优化我的代码.
我希望能够以与控制台中的Excel文件相同的方式进行排序.
事实上,我的最终目标是拿第一个文件,判断其中的问题,看看它们是否存在.然后,一旦我 Select 了问题,我将有两个看起来相同的文件,所以我必须比较它们,看看是否有任何差异.
这就是为什么我想知道如何在开始时进行排序.
先谢谢你.
package readAndPrint;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class read3file {
public static void main(String[] args) {
// Définir les fichiers et leur emplacements
String sPathDirectory ="C:\\Users\\...\\Downloads\\";
String pathFileQR = sPathDirectory + "QR.csv";
String pathFilePivot = sPathDirectory + "PivotSegmentQuestion.csv";
String pathFileNCL = sPathDirectory + "PivotSegmentQuestionNCL.csv";
//Lire et afficher QR.csv
readAndPrintFile(pathFileQR);
//Lire et afficher PivotSegmentQuestion.csv
readAndPrintFile(pathFilePivot);
//Lire et afficher PivotSegmentQuestionNCL.csv
readAndPrintFile(pathFileNCL);
}
//Methode pour lire les fichiers et les afficher
private static void readAndPrintFile(String filePath) {
String line = "";
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
while ((line = br.readLine()) !=null)
System.out.println(line);
System.out.println("Fichier trouvé: " + filePath); //Confirmation
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("Fichier introuvable :" + filePath); //Affichage message erreur
} catch (IOException e) {
e.printStackTrace();
}
}
}