exits adn copy file in java

The solution for “exits adn copy file in java” can be found here. The following code will assist you in solving the problem.

//java code
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyFileStream {

public static void main(String[] args) throws IOException {

var source = new File(“src/resources/bugs.txt”);
var dest = new File(“src/resources/bugs2.txt”);

try (var fis = new FileInputStream(source);
var fos = new FileOutputStream(dest)) {

byte[] buffer = new byte[1024];
int length;

while ((length = fis.read(buffer)) > 0) {

fos.write(buffer, 0, length);
}
}
}
}
//bugs.txt
Assasin bug, Avondale spider, Backswimmer,
Bamboo moth, Banana moth, Bed bug,
Black cocroach, Blue moon, Bumble Bee,
Carpenter Bee, Cattle tick, Cave Weta,
Cicada, Cinnibar, Click beetle, Clothes moth,
Codling moth, Centipede, Earwig, Eucalypt longhorn beetle,
Field Grasshopper, Garden slug, Garden soldier,
German cockroach, German wasp, Giant dragonfly,
Giraffe weevil, Grass grub, Grass looper,
Green planthopper, Green house spider, Gum emperor,
Gum leaf skeletoniser, Hornet, Mealybug,
Mites, Mole Cricket, Monarch butterfly,
Mosquito, Silverfish, Wasp,
Water boatman, Winged weta, Wolf spider,
Yellow Jacket, Yellow Admiral

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in