gpt4 book ai didi

java - 在java中读取文件时,字符之间存在空格

转载 作者:行者123 更新时间:2023-12-02 11:28:00 25 4
gpt4 key购买 nike

这是似乎编写的代码,但输出很奇怪。

import java.io.*;
public class Main {
public static void main(String args[]){
FileReader in = null;
try{
in = new FileReader("myFile.txt");
int c;
while ((c = in.read()) != -1) {
System.out.print((char)c);
}
}catch(IOException ie){
ie.printStackTrace();
}finally{
try{
if(in!=null){
in.close();
}
}catch(IOException ie){
ie.printStackTrace();
}
}
}
}

myFile.txt simple text file
输出 console

最佳答案

您的文件很可能没有“UTF-8”编码。您可以使用InputStreamReader指定编码或将文件编码更改为UTF-8

关于java - 在java中读取文件时,字符之间存在空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49479718/

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