Solved

How can copy an ascii file on another one?

Posted on 1998-09-03
1
146 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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
null output 3 42
jboss wildfly 10.1 10 436
Problem to Alipay 10 71
Is there a simpler dropbox system? 10 44
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

733 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