파일의 행 수를 토큰으로 분할하여 계산하고 싶습니다. 내 코드가 제대로 작동하지 않는 것 같아 누군가 조언을 해줄 수 있습니까? 미리 감사드립니다.회선 수, 토큰 화
import java.util.*;
import java.io.*;
public class kup
{
public static void main(String args[]) throws Exception
{
FileReader fileInput = new FileReader("C:\\save\\input.txt");
BufferedReader readInput = new BufferedReader(fileInput);
FileWriter fileOutput = new FileWriter("C:\\save\\output.txt");
PrintWriter outFile = new PrintWriter(fileOutput);
Scanner scanLine = new Scanner(readInput);
String textInput = scanLine.nextLine();
StringTokenizer stringtokenizer = new StringTokenizer(textInput);
int tokenCount = stringtokenizer.countTokens();
int lineCount = 0;
while(scanLine.hasNextLine())
{
while(stringtokenizer.hasMoreTokens())
{
String string = stringtokenizer.nextToken();
outFile.println(string);
}
lineCount++;
}
outFile.println("Number of words: " +tokenCount);
outFile.println("Number of lines: " +lineCount);
readInput.close();
outFile.close();
}
}
자바 7을 사용하는 경우가 너무 finally 블록을 독자/작가/스트림을 폐쇄, 또는 시도 -과 - 자원 문을 사용한다
주 일하니? –
출력 파일에 결과가 출력되지 않는다는 것을 알고 있습니다. –