public static void main(String[] args) throws FileNotFoundException {
File file = new File("D:\\testout.txt");
InputStream in = new FileInputStream(file);
List<List<String>> splitByNewLine = convertInputStreamToString(in);
for(List<String> data : splitByNewLine) {
System.out.println(data);
}
}
private static List<List<String>> convertInputStreamToString(InputStream file) {
List<List<String>> fileData = new ArrayList<>();
List<String> data = new ArrayList<String>();
try (BufferedReader fileContent = new BufferedReader(new InputStreamReader(file))) {
String strLine = null;
while ((strLine = fileContent.readLine()) != null) {
data = Arrays.asList(strLine.split("\t"));
fileData.add(data);
}
} catch (IOException e) {
System.out.println("InputError: %s" + e.getMessage());
}
return fileData;
}
ВЫХОД: [r1c1 = filename1, r1c2 = abc1, r1c3 = def1, r1c4 = ghi1, r1c5 = col51]
[r2c1 = filename2, r2c2 = abc2, r2c3 = def2, r2c4 = ghi2, r2c5 = col52]
[r3c1 = filename3, r3c2 = abc3, r3c3 = def3, r3c4 = ghi3, r3c5 = col53]
[r4c1 = filename4, r4c2 = abc4, r4c3 = def4, r4c4 = ghi4, r4c5 = col54]