Java读取csv文件乱码

时间:2023-02-10 07:25:33

后来改为这样就可以了:

public static List<FishTackleType> read(String path){
List<FishTackleType> fishTackleTypes=new ArrayList<FishTackleType>();
try{
File file=new File(path);
DataInputStream in=new DataInputStream(new FileInputStream(file));
BufferedReader br=new BufferedReader(new InputStreamReader(in,"utf-8"));
//读取直到最后一行
String line="";
while((line=br.readLine())!=null){
StringTokenizer st=new StringTokenizer(line,",");
while(st.hasMoreTokens()){
FishTackleType fishTackleType=new FishTackleType();
fishTackleType.setTypeId(Integer.parseInt(st.nextToken()));
fishTackleType.setName(st.nextToken());
fishTackleTypes.add(fishTackleType);
}
}
br.close();
}catch(Exception e){
e.printStackTrace();
}
return fishTackleTypes;
}