public static void main(String args[]) throws FileNotFoundException, IOException
{
FileReader in = new FileReader("/home/aoblah/Downloads/file1.txt");
BufferedReader br = new BufferedReader(in);
// Scanner in = null;
String answer = null;
String verb = null;
String line = null;
String [] split_npn = null;
String [] split_pn = null;
String [] split_dp2 = null;
String [] split_dp3 = null;
HashMap<String, HashMap<String, ArrayList<String>>> hmap = new HashMap<String, HashMap<String, ArrayList<String>>>();
try {
while ((line = br.readLine()) != null)
{
if(line.contains("verb"))
{
verb = line.substring(0, line.indexOf("("));
if(line.contains("npn")){
String test = line.substring(line.indexOf("npn"));
answer = test.substring(test.indexOf("npn"),test.indexof(']'));
answer = answer.replace(",", " ");
split_npn = answer.split(" ");
}
if(line.contains("pn")){
String test = line.substring(line.indexOf("pn"));
answer = test.substring(test.indexOf("pn"), test.indexOf(']'));
answer = answer.replace(",", " ");
split_pn = answer.split(" ");
}
if(line.contains("dp2")){
String test = line.substring(line.indexOf("dp2"));
answer = test.substring(test.indexOf("dp2"), test.indexOf(']'));
answer = answer.replace(",", " ");
split_dp2 = answer.split(" ");
}
if(line.contains("dp3")){
String test = line.substring(line.indexOf("dp3"));
answer = test.substring(test.indexOf("dp3"), test.indexOf(']'));
answer = answer.replace(",", " ");
split_dp3 = answer.split(" ");
}
}
if(split_npn != null){
ArrayList<String> npn = new ArrayList<String>();
hmap.put(verb, new HashMap<String, ArrayList<String>>());
for(int i = 1; i< split_npn.length; i++){
npn.add(split_npn[i]);
}
npn.trimToSize();
hmap.get(verb).put("npn", npn);
}
if(split_pn != null){
ArrayList<String> pn = new ArrayList<String>();
hmap.put(verb, new HashMap<String, ArrayList<String>>());
for(int i = 1; i< split_pn.length; i++){
pn.add(split_pn[i]);
}
pn.trimToSize();
hmap.get(verb).put("pn", pn);
}
if(split_dp2 != null){
ArrayList<String> dp2 = new ArrayList<String>();
hmap.put(verb, new HashMap<String, ArrayList<String>>());
for(int i = 1; i< split_dp2.length; i++){
dp2.add(split_dp2[i]);
}
dp2.trimToSize();
hmap.get(verb).put("dp2", dp2);
}
if(split_dp3 != null){
ArrayList<String> dp3 = new ArrayList<String>();
hmap.put(verb, new HashMap<String, ArrayList<String>>());
for(int i = 1; i< split_dp3.length; i++){
dp3.add(split_dp3[i]);
}
dp3.trimToSize();
hmap.get(verb).put("dp3", dp3);
}
System.out.println(hmap);
}
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
파일에서이 항목을 포함 같은 침착 - 자바 힙 공간
(
로 동사, NAUX, [nullobj, [DP2, 아래로], [DP3, 아래로]], 고요한).평온 (동사, [sg], 평온).
평온한 (동사, [sg, pl, en], 평온).
calm (동사, [pl, inf], calm).
진정 (verb, [ing], calm).
침착하게 (adv, mv, calmly).
평온 (명사, [sg], 평온).
나는 모든 동사, 그것과 관련된 전치사의 카테고리 및 전치사를 중첩 해시 맵에 저장하려고합니다. 동사와 관련된 특정 전치사 범주 만 인쇄 할 때 문제가 없지만 전체 해시 맵을 표시하면 프로그램이 실행되고 멈추지 않습니다 ... 공간 힙 오류에서 Java로 끝납니다. 이 메모리 문제를 어떻게 해결할 수 있습니까?
파일의 크기는 얼마나됩니까? – chickenpie
테스트 할 작은 파일로 시도해보십시오. –
이 게시물을 확인하십시오 : http://stackoverflow.com/questions/9619092/java-heap-space-hashmap-arraylist?rq=1 – chickenpie