Reading the all files inside the folder and writing the data that we need.
My file name: GOPS_Read_10042017.txt
GOPS_Read_10042017.txt contains the data below:
000000000HDRGAPS2017-04-2621.20.55000000296
TFIC260420175 2017-04-26Test INDIA PRIVATE LIMITED
TFIC9PUPP02178 2017-04-26Test INDIA PRIVATE LIMITED
IFIC267332 2017-03-15GLOBAL BUSINESS SOLUTIONS I
L267332111
999999999TRLGAPS2017-04-2621.20.55000000296000029563
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
public class InvoiceFinder {
/**
* @param args
*/
private static File[] getFileList(String dirPath) {
File dir = new File(dirPath);
File[] fileList = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("GOPS") &&name.endsWith(".txt");
}
});
return fileList;
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try {
File[] matchingFiles = getFileList("C:\\files");
System.out.println(matchingFiles.length);
for (int i=0;i<matchingFiles.length;i++){
BufferedReader br = new BufferedReader(new FileReader(matchingFiles[i]));
BufferedWriter bw=new BufferedWriter(new FileWriter("C:\\files\\output"+matchingFiles[i].getName().substring(14)+".txt"));
String sCurrentLine;
br.readLine();
while((sCurrentLine=br.readLine())!=null){
if ( !sCurrentLine.startsWith("L")&&(!sCurrentLine.startsWith("000000000")&&!sCurrentLine.startsWith("999999999"))){
bw.write("'"+sCurrentLine.substring(4, 28).trim()+"',");
bw.newLine();
}
}
br.close();
bw.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
My file name: GOPS_Read_10042017.txt
GOPS_Read_10042017.txt contains the data below:
000000000HDRGAPS2017-04-2621.20.55000000296
TFIC260420175 2017-04-26Test INDIA PRIVATE LIMITED
TFIC9PUPP02178 2017-04-26Test INDIA PRIVATE LIMITED
IFIC267332 2017-03-15GLOBAL BUSINESS SOLUTIONS I
L267332111
999999999TRLGAPS2017-04-2621.20.55000000296000029563
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
public class InvoiceFinder {
/**
* @param args
*/
private static File[] getFileList(String dirPath) {
File dir = new File(dirPath);
File[] fileList = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("GOPS") &&name.endsWith(".txt");
}
});
return fileList;
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try {
File[] matchingFiles = getFileList("C:\\files");
System.out.println(matchingFiles.length);
for (int i=0;i<matchingFiles.length;i++){
BufferedReader br = new BufferedReader(new FileReader(matchingFiles[i]));
BufferedWriter bw=new BufferedWriter(new FileWriter("C:\\files\\output"+matchingFiles[i].getName().substring(14)+".txt"));
String sCurrentLine;
br.readLine();
while((sCurrentLine=br.readLine())!=null){
if ( !sCurrentLine.startsWith("L")&&(!sCurrentLine.startsWith("000000000")&&!sCurrentLine.startsWith("999999999"))){
bw.write("'"+sCurrentLine.substring(4, 28).trim()+"',");
bw.newLine();
}
}
br.close();
bw.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
0 comments: