1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| package test;
import java.io.File;
import java.io.IOException;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import java.util.ArrayList;
import java.util.Arrays;
public class Test {
private static String filePath = "C:/Users/LD/Desktop/001.txt";
public static void main(String[] args) {
try {
String fileContent = Files.toString(new File(filePath), Charsets.ISO_8859_1);
String[] lines = fileContent.split("-1");
ArrayList<ArrayList<ArrayList<String>>> gram = new ArrayList<ArrayList<ArrayList<String>>>();
for (String line : lines) {
gram.add(readLine(line.trim()));
}
showArray(gram);
} catch (IOException e) {
e.printStackTrace();
}
}
private static ArrayList<ArrayList<String>> readLine(String line) {
ArrayList<ArrayList<String>> array_line = new ArrayList<ArrayList<String>>();
String[] first_split = line.split("=");
// j = 0
ArrayList<String> first_array = new ArrayList<String>();
first_array.add(first_split[0].trim());
array_line.add(first_array);
// j > 0
String[] second_split = first_split[1].split("\\|");
for (String string : second_split) {
ArrayList<String> new_array = new ArrayList<String>(Arrays.asList(string.trim().split(" ")));
array_line.add(new_array);
}
return array_line;
}
private static void showArray(ArrayList<ArrayList<ArrayList<String>>> gram) {
for (int i = 0; i < gram.size(); ++i) {
for (int j = 0; j < gram.get(i).size(); ++j) {
System.out.print("i = "+i+", j = "+j+", ");
for (int k = 0; k < gram.get(i).get(j).size(); ++k) {
System.out.print("k["+k+"] = "+gram.get(i).get(j).get(k)+", ");
}
System.out.print("\n");
}
System.out.print("\n");
}
}
} |
Partager