我正在尝试使用文件编写器编写文件,但值为null:
FileReader inCorpus2=new FileReader("output2.txt");
FileWriter outCorpus2=new FileWriter("Doc2(THE WANTED FILE).txt");
Scanner sc2=new Scanner(inCorpus2);
try{
while(sc2.hasNextLine()){
String tempLine=sc2.nextLine();
Scanner sc3=new Scanner(tempLine);
while(sc3.hasNext()){
String temp=sc3.next();
for(int i=0;i<UC.length;i++){
for(int j=0;j<temp.length();j++){
if(temp.charAt(j)==UC[i])temp=removeChar(temp,j);
}
}
这是错误按摩:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at aya.SecondFilePreproc.main(SecondFilePreproc.java:25)
我希望我很清楚,我尽我所能..请帮助我。
答案 0 :(得分:-1)
不确定是否有帮助,需要查看完整代码。刚添加了一些例外。
import java.io.*;
import java.util.Scanner;
public static String removeChar(String x,int y){
return "something";
}
public class SomeClass {
public static void main(String[] args) throws FileNotFoundException, IOException {
try(FileReader inCorpus2=new FileReader("output2.txt");
FileWriter outCorpus2=new FileWriter("Doc2(THE WANTED FILE).txt");
Scanner sc2=new Scanner(inCorpus2)
){
while(sc2.hasNextLine()){
String tempLine=sc2.nextLine();
Scanner sc3=new Scanner(tempLine);
while(sc3.hasNext()){
String temp=sc3.next();
//just a guess what is UC
//char UC[]={'A','B','C'};
}
for(int i=0;i<UC.length;i++){
for(int j=0;j<temp.length();j++){
if(temp.charAt(j)==UC[i])temp=removeChar(temp,j);
}
}
}
}
}
}