English, asked by akashk71102, 2 months ago

write a java program to copy a file into another file and delete first file​

Answers

Answered by Anonymous
0

Answer:

read() method

public int read(byte[] b) throws IOException

Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available. It returns total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached. In order to make this method work in our program, we have created a byte array “buffer” and reading the content of input file to the same. Since this method throws IOException, we have put the “read file” code inside try-catch block in order to handle the exception.

write() method

public void write(byte[] b,

                 int off,

                 int length)

          throws IOException

Writes length bytes from the specified byte array starting at offset off to this file output stream.

Tweaks:

If your input and outfile files are not in the same drive then you can specify the drive while creating the file object. For example if your input file is in C drive and output file is in D drive then you can create the file object like this:

File infile =new File("C:\\MyInputFile.txt");

File outfile =new File("D:\\MyOutputFile.txt");

Explanation:

Similar questions