gpt4 book ai didi

java - 读取文件 utf-8

转载 作者:行者123 更新时间:2023-11-29 07:54:01 25 4
gpt4 key购买 nike

<分区>

我写了下面的代码,它无法读取 utf-8 文件。我尝试在网上搜索文档,但无法纠正。

public List<Khach> readFile2(String fileName) {
List<Khach> resultThue = new ArrayList<Khach>();
try {
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line = reader.readLine();
while (line != null) {
String[] result = line.split(", ");

Khach k = new Khach();
k.setMaKhach(result[0]);
k.setTenKhach(result[1]);
resultThue.add(k);
line = reader.readLine();
}
reader.close();
} catch (FileNotFoundException e) {
System.err.println(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
}
return resultThue;
}

}

//在主类中:

import java.util.List;

public class Program {
public static void main(String[] args) {
XuLyFile fp = new XuLyFile();
List<Khach> rk = fp.readFile2("thue.txt");
for (Khach k : rk) {
System.out.println(k);
System.out.println();
}

}
}

文件 thue.txt:

K1, “Nguyễn A”, VIP:NOR,3,10, 5, M1-M3-M5

K2, “Nguyễn B”, VIP,2,15, 5, M1-M4-M5

K3, “Nguyễn C”, NOR,5,5, 5

K4, “Nguyễn D”, LOV,2,8, 5, M1-M2-M3

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com