Recuperer un tableau de byte avec une url
Bonjour
Je voudrais recuperer un fichier contenu dans une url (en localhost) dans un tableau de byte, mais j'obtiens une erreur.
Pouvez vous m'aider?
Merci d'avance
PS le fichier est correct et il existe bien
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
URL url = new URL("http://localhost/C:\\setupisam.log");
URLConnection uc = url.openConnection();
System.out.println("connection is opened");
ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
InputStream in = url.openStream();
byte[] buf = new byte[512];
int len;
while (true)
{
len = in.read(buf);
if (len == -1) {
break; }
tmpOut.write(buf, 0, len);
}
tmpOut.close();
byte[] data = tmpOut.toByteArray(); |
j'obtiens cette erreur:
Code:
1 2 3 4 5 6 7 8 9 10
|
connection is opened
Exception in thread "main" java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at essaiurl.main(essaiurl.java:57) |