Question: I have the following program but whenever I try to run it I get an error that it cannot find or load the main class.

I have the following program but whenever I try to run it I get an error that it cannot find or load the main class. Can you please take a look at it and tell me what to add to the comment area or tell me what is wrong with that causes the run to fail? Thank you.

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

public class CopyFileContent {

public static void main(String[] args) {

/* Comment Here */

File sourceFile = new File("file1.txt");

/* Comment Here */

File destFile = new File("file2.txt");

/* Comment Here */

if (!destFile.exists()) {

try {

destFile.createNewFile();

} catch (IOException e) {

e.printStackTrace();

}

}

InputStream input = null;

OutputStream output = null;

try {

/* Comment Here */

input = new FileInputStream(sourceFile);

/* Comment Here */

output = new FileOutputStream(destFile);

byte[] buf = new byte[1024];

int bytesRead;

while ((bytesRead = input.read(buf)) > 0) {

output.write(buf, 0, bytesRead);

}

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

finally {

try {

if (null != input) {

input.close();

}

if (null != output) {

output.close();

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!