Given the code fragment:public static void main(String[] args) {String source = "d:\\company\\info.txt";String dest = "d

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899566
Joined: Mon Aug 02, 2021 8:13 am

Given the code fragment:public static void main(String[] args) {String source = "d:\\company\\info.txt";String dest = "d

Post by answerhappygod »

Given the code fragment:public static void main(String[] args) {String source = "d:\\company\\info.txt";String dest = "d:\\company\\emp\\info.txt";//insert code fragment here Line **} catch (IOException e) {System.err.println ("Caught IOException: " + e.getmessage();Which two try statements, when inserted at line **, enable the code to successfully move the file info.txt to the destination directory, even if a file by the same name already exists in the destination directory?

A. try {FileChannel in = new FileInputStream(source).getChannel(); FileChannel out = new FileOutputStream(dest).getChannel (); in.transferTo (0, in.size(), out);
B. try {Files.copy(Paths.get(source), Paths.get(dest)); Files.delete(Paths.get(source));
C. try {Files.copy(Paths.get(source), Paths.get(dest)); Files.delete(Paths.get(source));
D. try {Files.move (Paths.get(source), Paths.get(dest)); E. try {BufferedReader br = Files.newBufferedReader(Paths.get(source), Charset.forName ("UTF-8")); BufferedWriter bw = Files.newBufferedWriter (Paths.get(dest), Charset.forName ("UTF- 8")); String record = ""; while ((record = br.readLine()) != null){ bw.write (record); bw.newLine(); } Files.delete(Paths.get(source));
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This question has been solved and has 1 reply.

You must be registered to view answers and replies in this topic. Registration is free.


Register Login
 
Post Reply