소스 코드에서 읽을 수있는 java에서 전 처리기를 만들려고합니다. 코드를 모두 하나의 문자열로 읽으려고했습니다.Java : 파일 판독기, 구분 기호로 구분 기호 도움말
질문 : < < < >>> 중간에있는 문자열을 일종의 자체 배열 목록에 어떻게 추가합니까?
public class processLines {
public void pLine (String FileName)throws IOException{
Scanner scanner = null;
try{
scanner = new Scanner(new BufferedReader(new FileReader(FileName)));
while (scanner.hasNext()) {
String Line = "";
String LineB = "";
String LineC = "";
ArrayList<String> inside = new ArrayList<String>();
Line = Line + scanner.next()+ " ";
System.out.println("outside token: "+ Line);
StringTokenizer token = new StringTokenizer(Line);
while(token.hasMoreTokens()&& token.nextToken() != null){
LineB = Line;
if(LineB.contains("<<<")){
if(!LineB.contains(">>>")){
LineC = LineC + scanner.next()+ " ";
inside.add(LineC);
System.out.println("LineC: " + LineC);
System.out.print(inside);
}
if(scanner.next(">>>") != null){
Line = scanner.next();
System.out.println("Line INside:" + Line);
}
}
}
}
}
finally {
if (scanner != null) {
scanner.close();
}
}
}
}
텍스트 파일 소스 코드는 "모 < < < 모 래리 곱슬 >>> 래리"한 줄에 모두 포함되어 있습니다. 이 코드는 < < < >>>의 중간에 하나의 이름 만 있으면 작동하지만 더 추가하면 오류가 발생합니다. 외부 토큰 : 발생
오류 메시지 모
외부 토큰 : < < < LineC : 모 [모] 글 예외 "메인"java.util.InputMismatchException java.util.Scanner에서 proProcess.main에서 processLines.pLine (processLines.java:26) 에서 java.util.Scanner.next (알 소스)에 java.util.Scanner.next (알 소스)에 .throwFor (알 소스) (proProcess.java:14)