Results 1 to 3 of 3
  1. #1
    devish is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default 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.
    Java 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();
    	}
    
    }
    #10373 - Mystic Paste

  2. #2
    devish is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default Solved: program throwing write exception


  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: program throwing write exception

    Uhm...

    The full exception and stacktrace might help.

Similar Threads

  1. Program not throwing exception
    By aedara in forum New To Java
    Replies: 3
    Last Post: 06-28-2011, 06:55 AM
  2. Exception throwing
    By andy16 in forum New To Java
    Replies: 9
    Last Post: 06-07-2010, 06:57 PM
  3. Main method throwing specific Exception
    By bugger in forum New To Java
    Replies: 5
    Last Post: 05-13-2009, 03:34 PM
  4. Display Message Without Throwing Exception
    By kailashchandra in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 09-27-2008, 10:05 AM
  5. throwing Exception
    By bugger in forum New To Java
    Replies: 3
    Last Post: 11-09-2007, 10:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •