[세] [부정하지만, 매우 긴] 지금까지 내가 코드를 다음 한동적 2D 자바 배열을 채우는
, 패턴 매처 (pattern matcher)를 사용하여 내가 찾고있는 입력 파일의 구성 요소를 찾아 낼 수는 있지만, 이것은 입력의 첫 번째 줄에 고착되어 반복적으로 입력 파일의 진행을 만드는 방법을 추가합니다 매번 배열에 새 행을 씁니다.
지금까지 내 코드는 다음과 같다 :public static void main(String[] args) throws IOException
{
BufferedReader br_0 = new BufferedReader(new FileReader("file.txt"));
String line_0;
//while the file is still reading
while ((line_0 = br_0.readLine()) != null)
{
int i = 0;
Pattern p = Pattern.compile("'(.*?)'(?![a-zA-Z])");
//count from zero
String[][] arr = new String[262978][3];
for (int count = 0; count < 262978; count++)
{
Matcher m = p.matcher(line_0);
int j = 0;
while (m.find())
{
arr[i][j++] = m.group(1);
}
i++;
}
}
br_0.close();
}
입력 파일은 다음과 같다 :
'end with'('the playing of the british national anthem', 'hong kong').
'follow at'('the stroke of midnight', 'this').
'take part in'('the ceremony', 'both countries').
'start at about'('# pm', 'the ceremony').
'end about'('# am', 'the ceremony').
'lower'('the british hong kong flag', '# royal hong kong police officers').
'raise'('the sar flag', 'another #').
'leave for'('the royal yacht britannia', 'the #').
'hold by'('the chinese and british governments', 'the handover of hong kong').
'rise over'('this land', 'the regional flag of the hong kong special administrative region of the people \'s republic of china').
'cast eye on'('hong kong', 'the world').
'hold on'('schedule', 'the # governments').
'be festival for'('the chinese nation', 'this').
'go in'('the annals of history', 'july # , #').
...
이상적으로 배열 인덱스는 다음과 같을 것이다 :
[0] 0] end with
[0] [1] the playing of the british national anthem
,210
[0] [2] hong kong
[1] [0] follow at
[1] [1] the stroke of midnight
[1] [2] this
[2- [0] take part in
[3] [1] the ceremony
[2] [2] both countries
이 같은이 시점 모양의 출력은 :
[45993][2] the president of the people \'s republic of china he mr jiang zemin
[45994][0] speak at
[45994][1] the ceremony
[45994][2] the president of the people \'s republic of china he mr jiang zemin
[45995][0] speak at
[45995][1] the ceremony
[45995][2] the president of the people \'s republic of china he mr jiang zemin
[45996][0] speak at
[45996][1] the ceremony
[45996][2] the president of the people \'s republic of china he mr jiang zemin
[45997][0] speak at
[45997][1] the ceremony
[45997][2] the president of the people \'s republic of china he mr jiang zemin
[45998][0] speak at
[45998][1] the ceremony
[45998][2] the president of the people \'s republic of china he mr jiang zemin
[45999][0] speak at
실제 출력을 추가 (또는 :-)을) – xmoex