Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can copy an ascii file on another one?

Posted on 1998-09-03
1
Medium Priority
?
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
msmolyak earned 100 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

596 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