Results 1 to 3 of 3
Thread: program throwing write exception
- 10-22-2011, 09:06 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 2
- Rep Power
- 0
program throwing write exception
hi,
Here i want to read words and then convert them to unicode(\udddd). The program is working fine even printing unicode but able to write
Can any one help.
#10373 - Mystic PasteJava Code:import java.io.*; /** * Reads file in UTF-8 encoding and output to STDOUT in ASCII with unicode * escaped sequence for characters outside of ASCII. */ public class UTF8ToAscii { public static void main(String[] args) throws Exception { // if (args.length < 1) java.io.BufferedWriter sout = new java.io.BufferedWriter( new java.io.OutputStreamWriter(new java.io.FileOutputStream( new java.io.File("resources/outputFile")), "ISO8859_1")); String line = "hi"; { // Directory path here String path = "resources"; String[] fl = new String[999]; int c = 0; String files; File folder = new File(path); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { files = listOfFiles[i].getName(); if (files.endsWith(".rc")) { fl[c] = files; System.out.println(fl[c] + "" + c); // System.out.println(files.getAbsolutePath()); ListFiles ls = new ListFiles(); { String Str = "resources/" + fl[c]; BufferedReader r = new BufferedReader( new InputStreamReader(new FileInputStream( Str), "UTF-8")); line = r.readLine(); while (line != null) { System.out.println(unicodeEscape(line)); line = r.readLine(); sout.write(line); } r.close(); } c++; } } } } } private static final char[] hexChar = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; private static String unicodeEscape(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if ((c >> 7) > 0) { sb.append("\\u"); sb.append(hexChar[(c >> 12) & 0xF]); // append the hex character // for the left-most // 4-bits sb.append(hexChar[(c >> 8) & 0xF]); // hex for the second group // of 4-bits from the left sb.append(hexChar[(c >> 4) & 0xF]); // hex for the third group sb.append(hexChar[c & 0xF]); // hex for the last group, e.g., // the right most 4-bits } else { sb.append(c); } } return sb.toString(); } }
- 10-23-2011, 03:24 PM #2
Member
- Join Date
- Oct 2011
- Posts
- 2
- Rep Power
- 0
Solved: program throwing write exception
solved
#10378 - Mystic Paste
- 10-24-2011, 10:01 AM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
Program not throwing exception
By aedara in forum New To JavaReplies: 3Last Post: 06-28-2011, 05:55 AM -
Exception throwing
By andy16 in forum New To JavaReplies: 9Last Post: 06-07-2010, 05:57 PM -
Main method throwing specific Exception
By bugger in forum New To JavaReplies: 5Last Post: 05-13-2009, 02:34 PM -
Display Message Without Throwing Exception
By kailashchandra in forum JavaServer Faces (JSF)Replies: 0Last Post: 09-27-2008, 09:05 AM -
throwing Exception
By bugger in forum New To JavaReplies: 3Last Post: 11-09-2007, 09:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks