package changeString;import java.io.FileNotFoundException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;public class changeString {static final String konma = ",";public static void main(String[] args) throws Exception {// TODO Auto-generated method stubString outStirng = null;Listinput = new ArrayList();
CsvUtil startFile = new CsvUtil("D:\\start.csv");
CsvUtil endFile = new CsvUtil("D:\\end.csv");
readFile rFile = new readFile();
input = rFile.readCsv("D:\\testfile.txt");
String str = null;
int start = 0;
int end = 0;
//System.out.println(startFile.getList().get(0));
//System.out.println(input.get(0));
//System.out.println(input.get(0).substring(3381, 3391));
for (int i = 0; i < input.size(); i++) {
for (int j = 0; j < startFile.getColNum(); j++) {
start = Integer.parseInt(startFile.getCol(j));
end = Integer.parseInt(endFile.getCol(j));
str = input.get(i).substring(start, end);
str = str + ",";
outStirng = outStirng + str;
}
outFile(outStirng);
}
}
public static void outFile(String string) throws Exception {
PrintWriter pWriter = new PrintWriter("D:\\outfile.txt");
pWriter.println(string);
pWriter.close();
}
}
package changeString;import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.List;public class readFile {public ListreadCsv(String path) throws IOException { String data = null;Listlist = new ArrayList<>();
String file = path;
try(BufferedReader br = new BufferedReader(new FileReader(file))) {
while ((data=br.readLine()) != null) {
list.add(data);
}
} catch (FileNotFoundException e) {
//Some error logging
}
return list;
}
}