?
Solved

How can copy an ascii file on another one?

Posted on 1998-09-03
1
Medium Priority
?
148 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

764 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