[JAVA100 Example]034, read-write file (character operation)

Source: Internet
Author: User

Import java.io.*;


/**


* <p>title: Read and write files (characters) </p>


* <p>description: Use the FileReader and FileWriter classes to manipulate files using character file access. </p>


* <p>copyright:copyright (c) 2003</p>


* <p>filename: </p>


* @version 1.0


*/


public class Copychar {


/**


*<br> Method Description: Main method


*<br> input Parameters:


*<br> return type:


*/


public static void Main (string[] args) throws IOException {


String sfile;


String ofile;


if (args.length<2) {


System.out.println ("Use:java Copychar source File | Object File ");


return;


}else{


sfile = args[0];


ofile = args[1];


    }


try{


FileName inputfile = new file (sfile);//define the Read source


file outputfile = new file (ofile);//define the target files for the copy


//define input file stream


FileReader in = new FileReader (inputfile);


//construct the file input stream to the cache


BufferedReader bin = new BufferedReader (in);


//define output file stream


FileWriter out = new FileWriter (outputfile);


//The output file stream is constructed to the cache


bufferedwriter bout = new BufferedWriter (out);


int C;


//loop read and input files.


while ((c = bin.read ())!=-1)


Bout.write (c);


Bin.close ();


Bout.close ();


}catch (IOException e) {


//File operation, capturing IO exception.


System.err.println (e);


    }


  }


}


import java.io.*;


/**


* <p>title: File read and write (character) </p>


* <p>description: Use the FileReader and FileWriter classes to manipulate files using character file access. </p>


* <p>copyright:copyright (c) 2003</p>


* <p>filename: </p>


* @version 1.0


*/


public class Copychar {


/**


*<br> Method Description: Main method


*<br> input Parameters:


*<br> return type:


*/


public static void Main (string[] args) throws IOException {


String sfile;


String ofile;


if (args.length<2) {


System.out.println ("Use:java Copychar source File | Object File ");


return;


}else{


sfile = args[0];


ofile = args[1];


    }


try{


Files Inputfile = new file (sfile);//definition Read source


file outputfile = new file (ofile);//define the target files for the copy


//define input file stream


FileReader in = new FileReader (inputfile);


//construct the file input stream to the cache


BufferedReader bin = new BufferedReader (in);


//define output file stream


FileWriter out = new FileWriter (outputfile);


//The output file stream is constructed to the cache


bufferedwriter bout = new BufferedWriter (out);


int C;


//loop read and input files.


while ((c = bin.read ())!=-1)


Bout.write (c);


Bin.close ();


Bout.close ();


}catch (IOException e) {


//File operation, capturing IO exception.


System.err.println (e);


    }


  }


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.