split UTF-8 string to multi UTF8-file

M

moonhkt

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) {
}

}
}
 
R

Roedy Green

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,730
Latest member
AudryNolan

Latest Threads

Top