我有以下代码来读取 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();
}
相关分类