줄에 물음표가 있는지 여부에 따라 텍스트 파일의 요소를 다른 배열로 나누고 싶습니다. 내가 가진 한 여기있다. 이indexOf를 사용하여 배열을 분리하기 위해 텍스트 파일의 행을 읽습니다.
Scanner inScan = new Scanner(System.in);
String file_name;
System.out.print("What is the full file path name?\n>>");
file_name = inScan.next();
Scanner fScan = new Scanner(new File(file_name));
ArrayList<String> Questions = new ArrayList();
ArrayList<String> Other = new ArrayList();
while (fScan.hasNextLine())
{
if(fScan.nextLine.indexOf("?"))
{
Questions.add(fScan.nextLine());
}
Other.add(fScan.nextLine());
}
indexOf는 정수를 반환하므로 코드를 컴파일하지 않은 것처럼 보입니다. 당신이 겪고있는 문제는 무엇입니까? – Vikdor
java는'if' 문에서'boolean '을 요구합니다. '.matches ("\?")'를 사용하십시오 (정규 표현식이지만 한 문자만으로 충분합니다.)'.indexOf ('?')> -1' – durron597