我有以下代碼來讀取 Java 中的 CSV 文件,使用 AES 算法加密數據,然后將加密的數據寫入另一個 CSV 文件。我目前收到此異常:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4 at encryption.Reading.main(Reading.java:45)有誰知道如何解決這個異常?我的 CSV 閱讀器(此代碼用于讀取給定的 CSV 文件)import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.List; public class Reading { public static void main(String[] args) throws Exception { Aes aes=new Aes(); String csvFile = "C:/Users/nana/Desktop/book1.csv"; String csvFile1 = "C:/Users/nana/Desktop/output.csv"; BufferedReader br = null; String line = ""; String cvsSplitBy = ","; int j=0; String[] studentArray = new String[4]; try { br = new BufferedReader(new FileReader(csvFile)); while ((line = br.readLine()) != null) { // use comma as separator String[] country = line.split(cvsSplitBy); String country1=""; for(int i=0;i<country.length;i++){ String password = country[i]; String passwordEnc = Aes.encrypt(password); country1=country1+passwordEnc+',';} studentArray[j]=country1; j=j+1; } Csvwrite.writeCsvFile(csvFile1, studentArray); }catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
添加回答
舉報
0/150
提交
取消