Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File in = new File("myfile.csv");
- InputStream fr = new FileInputStream(in);
- byte[] buffer = new byte[4096];
- while (true) {
- int byteCount = fr.read(buffer, 0, buffer.length);
- if (byteCount <= 0) {
- break;
- }
- String s = new String(buffer, 0, byteCount,"ISO-8859-1");
- System.out.println(s);
- }
- System.out.println(java.nio.charset.Charset.availableCharsets());
- System.out.println((int) s.getCharAt(index));
- System.out.println("Here's the character: u00f4");
- BufferedReader br = new BufferedReader(
- new InputStreamReader(
- new FileInputStream("myfile.csv"), "ISO-8859-1");
- char[] buffer = new char[4096]; // character (not byte) buffer
- while (true)
- {
- int charCount = br.read(buffer, 0, buffer.length);
- if (charCount == -1) break; // reached end-of-stream
- String s = String.valueOf(buffer, 0, charCount);
- // alternatively, we can append to a StringBuilder
- System.out.println(s);
- }
- public static void main(String[] args) throws IOException {
- byte[] data = { (byte) 0xF4 };
- String decoded = new String(data, "ISO-8859-1");
- if (!"u00f4".equals(decoded)) {
- throw new IllegalStateException();
- }
- // write default charset
- System.out.println(Charset.defaultCharset());
- // dump bytes to stdout
- System.out.write(data);
- // will encode to default charset when converting to bytes
- System.out.println(decoded);
- }
- 5554 462d 380a f4c3 b40a
Add Comment
Please, Sign In to add comment