try
{
BufferedReader br = new BufferedReader(
new FileReader(selectFile.getSelectedFile()));
String str;
ArrayList <String> lines = new ArrayList<String>();
while((str = br.readLine()) != null){
lines.add(str);
}
String[] LinesArray = lines.toArray(new String[lines.size()]);
System.out.println(lines); //Prints Array list on the screen.
br.close();
}
catch(IOException e)
{
System.out.println("The file cannot be read");
}
n 번째 단어을 파일에서 어떻게 인쇄 할 수 있습니까? 예를 들어, 사용자가 프로그램을 실행하고 단락이있는 파일을 선택하고 텍스트 파일의 12 번째 및 30 번째 단어를 인쇄하려고합니다.텍스트 파일에서 n 번째 단어 읽기
스플릿을 사용해 보았지만 나에게 적합하지 않았습니다. 제안 사항이 있으십니까?
1. 붙여 넣기 만 관련 코드. 2. 귀하의 코드를 인디고 제대로 포맷하십시오. 3. 파일 내용이 stringBuffer로 변환 될 수 있으므로 예상 결과가 출력 된 예제 입력 파일을 게시하십시오. – alfasin
StringBuffer에는 n 번째 문자열을 검색하는 데 좋은 API가 있습니다. subString (x, x + 1) – Zeus
@ 제우스는 n 번째 문자열이 아니라 n 번째 문자열입니다. – alfasin