[英]Getting file from URL - error
Thanks to this question( link ), I know how to download a file from the internet. 由于这个问题( 链接 ),我知道如何从互联网上下载文件。 However, instead of a normal Text in a txt-file i get a html response.
但是,我得到的是HTML响应,而不是txt文件中的普通文本。 Does anyone know what I'am doing wrong?
有人知道我在做什么错吗?
Here is my code: 这是我的代码:
// Install Authenticator
MyAuthenticator.setPasswordAuthentication("Username", "Password");
Authenticator.setDefault (new MyAuthenticator(Main.getPropertyPath()));
URL website = new URL("http://.../5-Anhang.txt?revision=1260");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("information.txt");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
EDITED 已编辑
Response: 响应:
<html>
<body onLoad='document.forms["login"].submit();'>
<form id='login' method='POST' action='/polarion/j_security_check'>
<input type='hidden' name='j_username' value='null'/>
<input type='hidden' name='j_password' value='null'/>
<noscript>
<input type='submit' value="Login"/>
</noscript>
</form>
</body>
</html>
Since comment is not readable, posting the answer. 由于注释不可读,请发布答案。
import java.io.*;
import java.net.*;
public class App {
public static void main(String[] args) throws Exception{
URL url = new URL("http://localhost:8080/js/txt1.txt");
// read text
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
}
}
Below code worked for to read a text file which is in below format 以下代码用于读取以下格式的文本文件
Novak Djokovic
Andy Murray
Roger Federer
Nishokiri
Output 输出量
Novak Djokovic
德约科维奇(Novak Djokovic)
Andy Murray
安迪·穆雷(Andy Murray)
Roger Federer
罗杰·费德勒
Nishokiri
西吉里
好像我可以在网页上搜索“ revision = 1260”类并将其返回
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.