0
프로젝트의 파일에서 단어와 해당 코드를 읽으려고합니다. 이 코드는 내가 가지고있는 코드이며 괜찮습니다. 일부 이유 때문에 공백이 코드의 일부가 아닌 모든 뒤에 추가됩니다. 나는 그것이 왜 일어나고 있는지 이해하지 못한다.파일을 읽는 중 공백을 추가했습니다 ...?
public void loadDictionary(String file){
String fileName=file;
String fileNameTwo=file;
//Coder c=new Coder();
String string;
String code;
String s=null;
try{//System.out.println("1");
FileReader freader=new FileReader(fileName);
FileReader freaderTwo=new FileReader(fileNameTwo);
//System.out.println("1");
BufferedReader inFile=new BufferedReader(freader);
BufferedReader inFileTwo=new BufferedReader(freaderTwo);
//System.out.println("2");
//System.out.println("3");
if ((s=inFile.readLine())==null){
System.out.println("5");
throw new EmptyFileException("Nothing in file to upload.");
}
while ((s=inFileTwo.readLine())!=null){
//System.out.println("4");
//System.out.println(s);
String[] tokens=s.split(" ");
string=tokens[0];
//System.out.println(string);
code=tokens[1];
//System.out.println(code);
this.insert(string, code);
System.out.println(code+".");
}//end while
//this.printCoder();
}//end try
catch(EmptyFileException ex){
}
catch(IOException ex){
System.out.println("Error in uploading dictionary.");
}
}//end method
... 및 출력 (코드)이다 :
코드는
5721.
9963.
4432 .
1143 .
6402 .
3333 .
4924 .
1429 .
3110 .
3036 .
2736 .
8064.
기간이 첨가 얼마나 많은 공간이 보여주고있는 I 단지. system.out.println()에 마침표를 추가했습니다.
편집 : 기간이 제대로 나오지 않고 있습니다.하지만 아이디어는 얻을 수 있습니다. 실제로는 때로는 더 많거나 적은 공백이 있습니다.
공간이 맞습니까? 액셀 레이션을 공백으로 나누기 때문에 탭이 될 가능성이 큽니다. 'String [] tokens = s.split ("\\ s +");'와 같이 나눠서 다시 시도하거나 출력에서 아무 것도 변경하는지 알려주세요. – amit
데이터를 확인하십시오. 'readLine()'은 공백이나 다른 것을 추가하지 않습니다. 데이터에 대한 유일한 작업은 * 줄 바꿈을 제거하는 것입니다. – EJP