我需要在java中读取3个csv文件。所以这一部分我已经完成了,但我想为下一部分优化我的代码。
我希望能够以与控制台中Excel文件相同的方式进行排序。
实际上我的最终目的是拿第一个文件,检查其中的问题,看看它们是否存在。然后,一旦我选择了问题,我将有两个文件看起来相同,所以我必须比较它们,看看是否有任何差异。
这就是为什么我想知道如何在开始时排序。
先谢了。
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();
}
}
}
字符串
1条答案
按热度按时间u5i3ibmn1#
字符串