如何从java中的网站读取.dat文件中的文本?

时间:2022-08-30 09:01:08

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

我正在使用java并尝试从网站上读取.dat文件,但它不起作用。我试过的是:

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.

我把示例url放在那里,但是在我的代码中它确实有.dat文件,在那个dat文件中它有很多文本。

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

它甚至没有显示错误,我试图看看错误是什么,但在catch语句中,它表示null。

Could I get a piece of advice please? Thanks

我能得到一条建议吗?谢谢

1 个解决方案

#1


0  

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
}

#1


0  

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
}