Solved

How can copy an ascii file on another one?

Posted on 1998-09-03
1
141 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
Comment Utility
// 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array6 challenfge 6 62
array220 challenge 8 44
pairstar challenge 2 41
eclipse formatting 6 38
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:

771 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

7 Experts available now in Live!

Get 1:1 Help Now