import java.util.*; import java.io.*; public class FileProcessor { private BufferedReader br = null; private BufferedWriter bw = null; private String line=null; private String output =""; private String errMsg =""; FileWriter fw= null; static String TAB = " "; public FileProcessor(){ } public void processFile(String src_file, String target_file){ StringTokenizer st = null; errMsg = ""; try { br = new BufferedReader(new InputStreamReader( new FileInputStream(src_file), "utf-8") ); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(target_file), "utf-8") ); //br = new BufferedReader(new InputStreamReader( new FileInputStream(src_file) ) ); //bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(target_file) ) ); File tf = new File(target_file); //remove line feeds with ";" int i = 0; int lineCounter = 0; //line = new StringBuffer(br.readLine()); while ( ( line = br.readLine() ) != null ) { lineCounter++; String ts =""; if (line != null ){ line = line.replace(',',';'); bw.write(line.toString()); } /*if (line != null ){ st = new StringTokenizer(line.toString(), ";"); output = ""; while( st.hasMoreTokens() ) { i++; output= st.nextToken().trim(); //System.out.println("writing "+i); output = output.substring(0,output.indexOf("=")); ts = ts +output+";"; } bw.write(ts); bw.flush(); } if (lineCounter % 2 == 0) { } else{ bw.write(line.toString()+","); }*/ bw.flush(); } /* StringTokenizer st2= null; String t = ""; //remove line feeds with ";" and remove other strings while ( ( line = br.readLine() ) != null ) { st = new StringTokenizer(line, "\n"); output = st.nextToken(); st2 = new StringTokenizer(output, ","); t= st2.nextToken(); output= st2.nextToken(); output = output.replace('[', '<'); output = output.replace(']', ':'); output = output.substring(0,output.indexOf("<"))+"=<"+output.substring(output.indexOf("<")+1, output.length()); output = output +t +">;"; bw.write(output); output=""; bw.flush(); } */ } catch (Exception ex) { errMsg = errMsg+"\nerror in read/write file... " + ex.toString() ; try { br.close(); fw.close(); } catch (Exception cl) { errMsg = errMsg + cl.toString(); } System.out.println(errMsg); } } }