알아낼 수 없습니다. 내 프로그램에서 텍스트를 쓰려고합니다. 그것은 단어 카운트 프로그램을 가정합니다. 나에게 줄 수, 문자 수, 단어 수를 보여주십시오. 그런 다음 사용자가 검색하는 단어와 그 행과 함께 결과를 표시합니다.버퍼링 된 출력이 잘못된 파일에 쓰기
(즉, 검색 자바)
라인 5 : 자바 섬 자바
라인 (9)을 포함 : 나는 자바 그것은 텍스트를 표시 아니에요
에게 술을 좋아한다. heiroglyphics와 같은 그것의 표시.
라인 2 : DN {c < \ $ H Uz X h4 [ bA. D Ja 8 ^) | k ˠ < ΤQJP˒nI "(vcBi"&/| qIW6 {PA0의 [[M ! FU } 4 배 {- (Vk을 우리는 T"을 ֭ @ 3 호선 : NU Ӣ ͇ ? 4 호선 : Ӻ 鬵 PD <} L> oVExQ |) 'gIB3b ("3 T 7 : : : : : : : : : : : : : : : : PK! N rels/.rels (
public void readFromFile(String filename)
{
LineNumberReader lineNumberReader = null;
try {
lineNumberReader = new LineNumberReader(new FileReader(filename));
String line = null;
BufferedWriter output = new BufferedWriter(new FileWriter("output.txt"));
String ask = "Enter Word";
String find = JOptionPane.showInputDialog(ask);
Scanner scan = new Scanner(new File("test.txt"));
while ((line = lineNumberReader.readLine()) != null)
{
line = scan.nextLine();
if(line.indexOf(find) >= -1)
{
output.write("Line " + lineNumberReader.getLineNumber() +
": " + line);
output.newLine();
}
}// end of while
output.close();
} // end of try
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
finally {
try {
if (lineNumberReader != null)
{
lineNumberReader.close();
}
} // end of try
catch (IOException ex)
{
ex.printStackTrace();
}
}// end of finally
} // end of function
에서 오는 파일에서 읽는 이유를 이해하지 않습니다. 훨씬 더 읽기 쉬울 것입니다! – Maccesch
while() 및 while 루프 내에서 루프 검사에서 줄을 겹쳐 쓰는 이유는 무엇입니까? 나는 당신의 프로그램이 무엇을하고 있는지조차 모르겠다 ... –
당신은 어떤 텍스트 편집기를 통해 당신의 파일을 읽으려고 하는가? – mawia