I have the following situation: I have a txt file of defined positions (type CSV, CNAB, etc.) to process and extract values. For purposes of understanding, follow the code I've made and it's working perfectly:
public class Extract {
final int[] CPF = new int[]{0, 10};
final int[] NOME = new int[]{15, 45};
public static void main(String args[]) {
FileInputStream fis = new FileInputStream("C:\cnab.txt");
String line;
while ((line = fis.readLine()) != null) {
System.out.println(getValue(line, CPF));
System.out.println(getValue(line, NOME));
}
}
private String getValue(String line, int[] slice) {
return line.substring(slice[0], slice[1]);
}
}
So long ok, but I would like something more readable, elegant, such as:
System.out.println(line.getValue(CPF));
But we all know that String is end . Anyone have any suggestions?