Parsing links from html file.

Part of the address is in English, part in Russian letters, for example:

http://roga.ru/article/news/kartinka1.jpg

When I try to open such a link with the help of this function and download the file, I just get the html http://roga.ru/article/

public HtmlToString(String url) throws Exception { URL pageURL = new URL(url); URLConnection uc = pageURL.openConnection(); String codePage = "windows-1251"; BufferedReader br = new BufferedReader( new InputStreamReader( uc.getInputStream(), codePage)); try { String inputLine; while ((inputLine = br.readLine()) != null) { this.sb.append(inputLine); } } finally { br.close(); } } public static void downloadFile(URL url, String filename) { try { ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream(filename); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } catch (IOException e) { e.printStackTrace(); } } 

Can anyone help with advice please?

Well, plus if you display such a link in the Intellij Idea console, then the clickable part is in English, and Russian letters are simply text.

    1 answer 1

    Only one encoding is allowed in the URL - ASCII; see the HTML URL Encoding Reference . To convert the URL to the correct type, use java.net.URLEncoder and java.net.URLDecoder