|
Read/Find Substring/Write to new file
Hi guys,
i would appreciate your help on this . I am trying to create a little program for myself. I needed a program to read a file and find 0000 (4 zeros) from that file and give me a number before each 4 zeros along with the 4 zeros and write it in a different file for me but each of the number in this new file should be in different line.
example:
10000 2121000044540000 0012000
Output
10000
10000
40000
This is what i have until now and i am stuck.
Please help
import java.io.*;
class FileReadTest
{
public static void main(String args[])
{
try{
FileInputStream fstream = new FileInputStream("c:/MyFile.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
FileWriter fstream1 = new FileWriter("c:/out.txt");
BufferedWriter out = new BufferedWriter(fstream1);
while ((strLine = br.readLine()) != null)
{
System.out.println (strLine);
out.write(strLine);
}
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
|