日期:2014-05-17  浏览次数:20655 次

新手求教IO问题
读出的数据出现多余的字符
代码如下:

package com.practice.test;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class test {


public static void main(String [] agrs) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("D:/user.txt"), "UTF-8"));
boolean inext=false;
StringBuffer sb=new StringBuffer();
while(!inext){
int c=br.read();
sb.append((char)c);
if(c==-1)
inext=true;
}
System.out.println(sb);
br.close();
}
}
下面是读出的数据:
?{"page":1,"records":3,"rows":[{"username":"yinpeng","userid":001,"usernote":"yinpeng"},{"username":"yinpeng","userid":002,"usernote":"yinpeng"},{"username":"yinpeng","userid":003,"usernote":"yinpeng"},{"username":"yinpeng","userid":004,"usernote":"yinpeng"}],"total":1}?
为什么开头结尾都有个"?"怎么解决?文件里开头什么都没有 包括空格和换行

------解决方案--------------------

你最后的?我知道为什么,因为你
Java code
while(!inext){
int c=br.read();
sb.append((char)c);
if(c==-1)
inext=true;
}