It is a simple attempt to parse a file using a simple logic. the program using Java I/O classes to read and write the text files.
import java.io.FileReader; import java.io.FileWriter; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; class FileParse{ public static void main(String arg[]){ FileParse ssObj = new FileParse(); try { BufferedReader in = new BufferedReader(new FileReader("SampleDataRead.txt")); // input text file String inputLine; int tmp=0; while ((inputLine = in.readLine()) != null) { tmp++; ssObj.process(inputLine); System.out.println("Processing line "+tmp+"...");} in.close(); } catch (IOException e) { System.out.println("There was a problem while reading: " + e); } } void process(String inputString){ char charAry[] = inputString.toCharArray();// breaking into characters try { BufferedWriter out = new BufferedWriter(new FileWriter("SampleDataWrite.txt",true)); // true - appending // Output file for(int i=0;i<charAry.length;i++) { if(charAry[i]==' ') out.write(charAry[i]+"#"); // # indicates End of word else{ if(i<(charAry.length-1)) out.write(charAry[i]+"$"); // $ indicated between every word else out.write(charAry[i]+"_|"); // _| indicates End of Line } } out.newLine(); out.close(); }catch(IOException e){ System.out.println("There was a problem while writing:" + e); } } }