重い .txt ファイルがあります。次のような形式が含まれています。
0 1 2 3 4 5 6 7 ... n
0 A, B, c, D, E, F, G, H,
1 AA, BB, CC, DD, EE, FF, GG, HH,
2
3
.
.
n
各行をマップに保存したい。たとえば、最初の行: map<0,A> 。map<1,B>, Map<2,C>,... 次に、このマップをリストに保存します。たとえば、リストに 100 行を保存したいとします。たとえば、次の関数を記述した場合: "" list.get(1).get(4); "" 私は "EE" を受け取りました。つまり、最初に 1 行に移動し、次に 4 に移動して "EE" を受け取ります。この問題を解決する方法を教えてください。「春のバッチ」に関する記事を読みました。それは私が望むものに関連しています。この問題を解決するにはどうすればよいですか?
public class spliter {
static int w=0;
private static HashMap<Integer,String> map = new HashMap<Integer,String>();
private static List<Map<Integer, String>> list=new ArrayList<Map<Integer,String>>();
public static void main(String[] args) throws IOException{
String string = null;
try {
BufferedReader reader = new BufferedReader(new FileReader("C:\\test.txt"));
while( (string = reader.readLine()) != null ) {
String[] parts = string.split(",");
int i=parts.length;
for(int j=0; j<i; j++){
map.put(j, parts[j]);
}
list.add(map);
w++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}