The following code retrieves for me a URL content and save it into a file:
URI obj_uri = new URI(uri);
URLConnection connection = obj_uri.toURL().openConnection();
connection.connect();
byte[] buffer = new byte[1024];
String filename = "temp";
try (InputStream in = connection.getInputStream(); FileOutputStream writer = new FileOutputStream( new File(filename) )) {
int len;
while ( (len = in.read(buffer)) != -1) {
writer.write( buffer, 0, len );
}
}
return filename;
My problem is, when this URI has a different symbol, as for example "http://dbpedia.org/resource/BrasÃlia", the content cannot be retrieved. The URL encoding used by DBpedia is UTF-8, and even using URLEncoder.encode( url, "UTF-8")
my code is not working. But my code does not generates an error or exception, the produced file ("temp") ends with no information (besides "" and "").
So, if the URI is correct and may be accessible even with its symbols, why I cannot retrieve its content and save it into a file?
Thank you for the help!