开发者

get content from website with utf8 format

开发者 https://www.devze.com 2022-12-25 14:02 出处:网络
i want how to get the content from websites with utf8 format,, i have writing the following code is try {

i want how to get the content from websites with utf8 format,,

i have writing the following code is

try {
        String webnames = "http://pathivu.com";

        URL url = new URL(webnames);

        URLConnection urlc = url.openConnection();

        //BufferedInputStream buffer = new BufferedInputStream(urlc.getInputStream());
        BufferedReader buffer = new BufferedReader(new InputStreamReader(urlc.getInputStream(), "UTF8")开发者_StackOverflow中文版);

        StringBuilder builder = new StringBuilder();

        int byteRead;

        while ((byteRead = buffer.read()) != -1)
            builder.append((char) byteRead);

        buffer.close();

        String text=builder.toString();

        System.out.println(text);
    } 
catch (IOException e) 
{
    e.printStackTrace();

}

but i cant get the correct format...

thanks and advance..


The problem might be that your console or your System.out are not UTF-8.

  • Try writing this to a file instead
  • Set the console stream via System.setOut(..)

You may have to use -Dfile.encoding=utf-8 or OutputStreamWriter


Your code looks ok.. the problem here it will be that in server the data will not be in UTF-8 format..

0

精彩评论

暂无评论...
验证码 换一张
取 消