public static void TempPreProcessor_Fixed(String input, String output){ BufferedReader reader = null; BufferedWriter writer = null; try { String inputfilename = input; String outputfilename = output; reader = new BufferedReader( new InputStreamReader( new FileInputStream(inputfilename))); writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(outputfilename))); String thisLine = null; //line 1 if((thisLine =reader.readLine()) != null) writer.write("AA,"+thisLine+"\n"); //line 2-4 for(int i = 0; i<3; i++){ if((thisLine =reader.readLine()) != null) writer.write(thisLine+"\n"); } //remaining lines while((thisLine=reader.readLine()) != null){ //add AB to start of line writer.write("AB,"+thisLine+"\n"); //copy with no change if((thisLine=reader.readLine()) != null) writer.write(thisLine+"\n"); } }catch(Exception e){ throw new ServiceException("TempPreProcessor: Unknown errors: " + e.toString()); }finally{ try{ if(writer != null) writer.flush(); if(reader != null) reader.close(); if(writer != null) writer.close(); reader=null; writer=null; }catch(Exception e){ throw new ServiceException("TempPreProcessor: Unknown errors: " + e.toString()); } } }
Thursday, February 24, 2011
Java Read/Write Fixed Length file sample
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment