java读取文本内容最后有个问号

aJiaosu 2019-01-09 06:55:39
最后有个空格,为什么读取文本内容后再输出会有个问号

...全文
228 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
尼坤神 2019-01-10
  • 打赏
  • 举报
回复

BufferedReaderbr = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "UTF-8"));
panhw176 2019-01-09
  • 打赏
  • 举报
回复
引用 2 楼 qq_41006771的回复:


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

class Document {
String filePath;
public Document(String fileName) {
this.filePath=fileName;
}
public String getContent() {
File file=new File(filePath);
StringBuilder result = new StringBuilder();
try{
BufferedReader br = new BufferedReader(new FileReader(file));
String s = null;
while((s = br.readLine())!=null){
result.append(System.lineSeparator()+s);
}
br.close();
}catch(Exception e){
e.printStackTrace();
}
return result.toString();
}
}

public class Main {

public static void main(String[] args) {
Document test=new Document("F:\\51060");
System.out.println(test.getContent());
}
}
我猜是换行符的关系?
aJiaosu 2019-01-09
  • 打赏
  • 举报
回复


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

class Document {
String filePath;
public Document(String fileName) {
this.filePath=fileName;
}
public String getContent() {
File file=new File(filePath);
StringBuilder result = new StringBuilder();
try{
BufferedReader br = new BufferedReader(new FileReader(file));
String s = null;
while((s = br.readLine())!=null){
result.append(System.lineSeparator()+s);
}
br.close();
}catch(Exception e){
e.printStackTrace();
}
return result.toString();
}
}

public class Main {

public static void main(String[] args) {
Document test=new Document("F:\\51060");
System.out.println(test.getContent());
}
}
十八道胡同 2019-01-09
  • 打赏
  • 举报
回复
你的代码咋写的?

50,543

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧