简体   繁体   中英

How can I read text in a .dat file from the website in java?

I'm using java and trying to read .dat file from the web site but it doesn't work. What I've tried is:

URL url = new URL("http://myExample.com/Example.dat");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));

I put example url there, but in my code it does have existing .dat file and in that dat file it has full of text.

It doesn't even show an error, I was trying to see what the error is but in the catch statement, it says null .

Could I get a piece of advice please? Thanks

You are not showing enough code to determine what is wrong. But for reference, the following works:

URL url = new URL("http://google.com");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String line = null;
while((line = br.readLine()) != null){
    //print line
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM