java.lang.Object | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.io.Reader | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.io.InputStreamReader | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
An InputStreamReader is a bridge from byte streams to character streams.
Constructor | Summary |
---|---|
InputStreamReader(InputStream in) | Creates an InputStreamReader that uses the default charset. |
InputStreamReader(InputStream in, Charset cs) | Creates an InputStreamReader that uses the given charset. |
InputStreamReader(InputStream in, CharsetDecoder dec) | Creates an InputStreamReader that uses the given charset decoder. |
InputStreamReader(InputStream in, String charsetName) | Creates an InputStreamReader that uses the named charset. |
Return | Method | Summary |
---|---|---|
void | close() | Closes the stream and releases any system resources associated with it. |
String | getEncoding() | Returns the name of the character encoding being used by this stream. |
int | read() | Reads a single character. |
int | read(char[] cbuf, int offset, int length) | Reads characters into a portion of an array. |
boolean | ready() | Tells whether this stream is ready to be read. |
Create BufferedReader from InputStreamReader and URL
import java.io.InputStreamReader;
import java.net.URL;
public class Main {
public static void main(String[] args) throws Exception {
URL myURL = new URL("http://www.google.com");
InputStreamReader so = new InputStreamReader(myURL.openStream());
while (true) {
int output = so.read();
if (output != -1) {
System.out.println((char)output);
} else {
break;
}
}
so.close();
}
}
Create InputStreamReader with encoding
import java.io.InputStreamReader;
import java.net.URL;
public class Main {
public static void main(String[] args) throws Exception {
URL myURL = new URL("http://www.google.com");
InputStreamReader so = new InputStreamReader(myURL.openStream(),"8859_1");
while (true) {
int output = so.read();
if (output != -1) {
System.out.println((char)output);
} else {
break;
}
}
so.close();
}
}
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |