From: moonhkt on 26 Jan 2010 09:13 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) { } } }
From: Roedy Green on 27 Jan 2010 02:12 On Tue, 26 Jan 2010 06:13:45 -0800 (PST), moonhkt <moonhkt(a)gmail.com> wrote, quoted or indirectly quoted someone who said : >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 ? 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 Canadian Mind Products http://mindprod.com Don�t be discouraged by a failure. It can be a positive experience. Failure is, in a sense, the highway to success, inasmuch as every discovery of what is false leads us to seek earnestly after what is true, and every fresh experience points out some form of error which we shall afterwards carefully avoid. ~ John Keats (born: 1795-10-31 died: 1821-02-23 at age: 25)
|
Pages: 1 Prev: Using browser's proxy-settings from a javaws-app? Next: Read utf-8 char one by one |