Solved

How can copy an ascii file on another one?

Posted on 1998-09-03
1
142 Views
Last Modified: 2010-03-30
I have to copy a file "xxxx.txt" on another "yyyyy.txt". How can i do? I see in IO package there isn't this method in class FILE. Thanks for helping me. Gonne.
0
Comment
Question by:gonne
1 Comment
 
LVL 5

Accepted Solution

by:
msmolyak earned 50 total points
ID: 1223488
// Open an input stream which allows you to read the source file.
BufferedReader reader = new BufferedReader(new FileReader(srcFileName));

// Open an output stream which allows to write to a destnation file.
BufferedWriter writer = new BufferedWriter(new FileWriter(destFileName));

// Create a buffer of some reasonable size. The reading and writing will be done
// in chunks of that buffer size.
char[] buffer = new buffer[4096];

int bytesRead;
while ((bytesRead = reader.read(buffer, 0, buffer.length)) > 0)
{
  writer.write(buffer, 0, bytesRead);
}

// Close streams
reader.close();
writer.close();

You will also have to take care of IOException handling.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now