Java inputstreamreader的输出与URL中的数据不匹配?

时间:2019-01-13 16:37:04

标签: inputstream

//Will read the contents of a txt file (one integer per line) and print to 
//console
import java.net.*;
import java.io.*;


public class WebPagesStats {

public static void main(String[] args) throws IOException {
    try {   //find my website and the txt file
        URL mySite = new URL("http://sites.google.com/site/"
                + "stephenkofflercodingprojects/"
                + "files-to-download/CBS%2020181223%20PAGEVIEWS.TXT");
        URLConnection myConnection = mySite.openConnection();   //open 
        connection
        InputStream input = myConnection.getInputStream();  //get 
        inputStream

        BufferedReader in;  // For reading from the connection's input 
         stream.
         in = new BufferedReader( new InputStreamReader(input) );


         while(in.read() != -1 )  {


             System.out.println(in.read()); //Print each line of 
          BufferedReader
         }
        } 
    catch (IOException e) {//IO Exception if file not found

        e.printStackTrace();
    }
    }

//output has numbers on each line, but not the ones in the file.
}//end

//前四行比较

输出
13

50

10

49

CBS 20181223 PageViews.txt

1

2

11

4

我还可以在此处添加其他内容来使问题得到接受吗?我已经评论了几乎每一行。我被简化为只输入意识流以使系统接受我的问题!!!!我非常努力地弄清楚了这一点,参考了几本教科书,问我的教授,我认识的其他人,和我一起工作过的Java导师。都被困住了。我真的不明白提出“好”问题的标准。

0 个答案:

没有答案