J
Jean-Benoit MORLA
Hi,
I have a program from a textbook that reads an ASCII file and prints
it in a JTextArea.
Now I would like to modify it so that it copies the input file to
an output file.
Here is the code:
File name = new File( actionEvent.getActionCommand() );
File nomfichier = new File( "FileCopied.txt" );
..
..
try {
BufferedReader input = new BufferedReader(
new FileReader( name ) );
PrintWriter output =
new PrintWriter( new BufferedWriter ( new FileWriter( nomfichier ) )
);
StringBuffer buffer = new StringBuffer();
String text;
outputArea.append( "\n\n" );
while ( ( text = input.readLine() ) != null )
{
buffer.append( text + "\n" );
output.write( text );
System.out.println( text );
}
outputArea.append( buffer.toString() );
} // end try
The program displays the input file in the JTextArea and the
System.out.println( text ) works.
But the output file exists but contains 0 bytes.
I have searched the Sun Java api but found nothing on the subject.
Can someone help me?
Many thanks
(e-mail address removed)
I have a program from a textbook that reads an ASCII file and prints
it in a JTextArea.
Now I would like to modify it so that it copies the input file to
an output file.
Here is the code:
File name = new File( actionEvent.getActionCommand() );
File nomfichier = new File( "FileCopied.txt" );
..
..
try {
BufferedReader input = new BufferedReader(
new FileReader( name ) );
PrintWriter output =
new PrintWriter( new BufferedWriter ( new FileWriter( nomfichier ) )
);
StringBuffer buffer = new StringBuffer();
String text;
outputArea.append( "\n\n" );
while ( ( text = input.readLine() ) != null )
{
buffer.append( text + "\n" );
output.write( text );
System.out.println( text );
}
outputArea.append( buffer.toString() );
} // end try
The program displays the input file in the JTextArea and the
System.out.println( text ) works.
But the output file exists but contains 0 bytes.
I have searched the Sun Java api but found nothing on the subject.
Can someone help me?
Many thanks
(e-mail address removed)