글쓴이 :박경수 2000년 5월 30일 17:47:22
In Reply to: 한글이 깨져서 나오는데 어떻게 하지요? posted by 박경수 on 2000년 5월 25일 16:44:16:
스트림으로 읽을 때 8bit트가 아닌 16bit로 읽으니까 되는 군요.
import java.net.*;
import java.io.*;
import java.lang.*;
public class URLRead
{
public static void main(String args[]) throws Exception
{
try
{
if (args.length != 1)
{
System.err.println ("Invalid command parameters");
System.in.read();
System.exit(0);
}
URL url = new URL(args[0]);
InputStream in = url.openStream();
// InputStream를 InputStreamReader로 바꾸었습니다.
InputStreamReader bufIn = new InputStreamReader(in);
for (;;)
{
int data = bufIn.read();
if (data == -1)
break;
else
System.out.print((char)data);
}
}
catch (MalformedURLException mue)
{
System.err.println ("Invalid URL");
}
catch (IOException ioe)
{
System.err.println ("I/O Error - " + ioe);
}
}
}