
i am trying to write a program that reads a text file and writes it to another directory. the main purpose of this program is to take the text file then read it and write it into as a comma delimitade file. i have to problem:
everything is perfect but when it comes to writing my program also adds commas to the extra white space.
the file that its reading is like a report file it has two fields, the left and write field i write out only the right field. as it is a report it has more than one log of information so my second problem is how to print each log within the file on separate line. the log start with "tAC" and ends with "->0|0|6" as you shall see in the text file i have posted below:
here is the code to what i have done thank you looking forward to your awesome replies
package elite.tech.com;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
public class Firstread extends Thread{
static String inpath = "C:\\Users\\ndayala\\asc";
static String outpath = "C:\\Users\\ndayala\\bin\\bin.txt";
public void runn1() throws IOException{
PrintWriter pw = new PrintWriter(new FileOutputStream(outpath ));// write to the outpath dir
File file = new File(inpath);//files from the inpath
File[] files = file.listFiles();//listFiles all file in inpath dir
for (int i = 0; i < files.length; i++) {
System.out.println("Processing " + files[i].getPath() + "... ");
BufferedReader br = new BufferedReader(new FileReader(files[i].getPath()));
String line = br.readLine();
while (line != null) {
line = line.replaceAll("\\s+","" );
line = line.replace("mSOriginatingSMSinMSC","" );
line = line.replace("GSMPLMNCallDataRecord","" );
line = line.replace("tAC","" );
line = line.replace("callIdentificationNumber","" );
line = line.replace("recordSequenceNumber","" );
line = line.replace("typeOfCallingSubscriber","" );
line = line.replace("callingPartyNumber","" );
line = line.replace("callingSubscriberIMSI","" );
line = line.replace("callingSubscriberIMEI","" );
line = line.replace("dateForStartofCharge","" );
line = line.replace("->0|0|6","" );
if(line.endsWith(",,")){
line = line.replace(",,","" );
}
System.out.println("writting:........"+files[i]);
char delim =',';
pw.print(line+delim);
line = br.readLine();
}
br.close();
}
pw.close();
System.out.println("your file have been concatenaded into one file under directory "+outpath);
//convert(outpath);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.