0
파일 test.txt
을 읽으려고 하나씩 단어를 모두 읽은 다음 읽은 단어에서 점과 쉼표를 제거하려고합니다. 여기 문자열에서 전체 제거 제거
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Utils {
public static void readFile(){
Scanner word = null;
try {
word = new Scanner(new File("test.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while (word.hasNextLine()) {
Scanner s2 = new Scanner(word.nextLine());
Utils.cleanWord(s2);
while (s2.hasNext()) {
String s = s2.next();
System.out.println(s);
}
}
}
private static void cleanWord(String word){
word = word.replace(".", "");
}
내 코드를 컴파일 할 때, 나는 Error:(18, 29) java: incompatible types: java.util.Scanner cannot be converted to java.lang.String
사람이 그것을 제거를 수행 할 수 있도록 내가 cleanWord
방법하시기 바랍니다에 제공해야하는 유형을 알고 있나요이 오류를 얻을 단어에 대한 조작. s2
이 Scanner
아닌 String
입니다 당신은 Utils.cleanWord(s2)
를 호출