Java Scanner 读取textfile 后有乱码(textfile 内容为英文,但是一个名字有括号)
privatevoidcreateList()throwsFileNotFoundException{FileInputStreaminputFile=newFileIn...
private void createList() throws FileNotFoundException {
FileInputStream inputFile = new FileInputStream("./resource/Database.txt");
Scanner in = new Scanner(inputFile);
int i = 0;
while (in.hasNext()) {
try {
species = in.next();
sawPat = in.next();
thickness = in.nextInt();
price = in.nextDouble();
Board board = new Board(species, sawPat, thickness, price);
System.out.println(board);
boardList.addLast(board);
} catch (InputMismatchException e) {
JOptionPane.showMessageDialog(null,
"The format of database is wrong!");
break;
}
}
} 展开
FileInputStream inputFile = new FileInputStream("./resource/Database.txt");
Scanner in = new Scanner(inputFile);
int i = 0;
while (in.hasNext()) {
try {
species = in.next();
sawPat = in.next();
thickness = in.nextInt();
price = in.nextDouble();
Board board = new Board(species, sawPat, thickness, price);
System.out.println(board);
boardList.addLast(board);
} catch (InputMismatchException e) {
JOptionPane.showMessageDialog(null,
"The format of database is wrong!");
break;
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询