split UTF-8 string to multi UTF8-file

Discussion in 'Java' started by moonhkt, Jan 26, 2010.

  1. moonhkt

    moonhkt Guest

    Hi All
    I have one utf-8, I want split input file into multi UTF-8. Can I
    using str.substring to extract string ? When input file have BOM code,
    how to remove the BOM code ?


    import java.nio.charset.Charset ;
    import java.io.*;
    import java.lang.String;
    public class read_utf {
    public static void main(String[] args) {
    File aFile = new File("input.txt");
    File oFileDetail = new File("input_det.html");
    File oFileHeader = new File("input_hdr.html");
    File oFileSKU = new File("input_sku.html");
    try {
    System.out.println("Header");
    System.out.println("Detail");
    System.out.println("SKU");
    String str = "";
    BufferedReader in = new BufferedReader(
    new InputStreamReader(new FileInputStream(aFile), "UTF8"));
    BufferedWriter outh = new BufferedWriter(
    new OutputStreamWriter(new FileOutputStream
    (oFileHeader),"UTF8"));
    BufferedWriter outdet = new BufferedWriter(
    new OutputStreamWriter(new FileOutputStream
    (oFileDetail),"UTF8"));
    BufferedWriter outsku = new BufferedWriter(
    new OutputStreamWriter(new FileOutputStream
    (oFileSKU),"UTF8"));

    while (( str = in.readLine()) != null )
    {
    System.out.println(str.length());
    outh.write(str.substring(1,10));
    outh.newLine();
    outdet.write(str);
    outdet.newLine();
    outsku.write(str.substring(167,178));
    outsku.newLine();
    }
    outh.close();
    outdet.close();
    outsku.close();
    } catch (UnsupportedEncodingException e) {
    } catch (IOException e) {
    }

    }
    }
     
    moonhkt, Jan 26, 2010
    #1
    1. Advertisements

  2. John B. Matthews, Jan 26, 2010
    #2
    1. Advertisements

  3. moonhkt

    Roedy Green Guest

    Unfortunately Readers don't filter out BOMs. What can you do?

    see http://mindprod.com/jgloss/bom.html#AVOIDING

    for 5 not-entirely satisfactory solutions.

    I could implement one of these solutions for a nominal fee.
     
    Roedy Green, Jan 27, 2010
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.