Computer Science, asked by MrTSR, 3 days ago

J A V A
1. Write a program to copy a file to another file using Java to package classes. Get the
file names at run time and if the target file is existed then ask confirmation to
overwrite and take necessary actions.
2nd. Program to get file name at runtime and display number f lines and words in
that file.

Answers

Answered by Oreki
6

\textsf{\large Files class}

   \textsf{\textemdash \: Contains static methods that work on files.}\\\textsf{\textemdash \: Utilized f\symbol{111}r fundamental file manipulations like make, read, compose,}\\\textsf{\hspace{1.3em} duplicate and erase a file.}

    \texttt{Methods}

        \textsf{readAll\symbol{76}ines(...), write(...), copy(...), size() etc.}

\textsf{Question - 1}

    \textsf{22 : A file's absolute path can be provided or if the file is in the current directory}\\\textsf{\hspace{1.8em} the file n\symbol{97}me is sufficient.}\\\textsf{30 - 3 : Used the \textbf{Files} class from \textbf{java.nio} package for file I/O.}

    \textsf{Can be rewritten using the \texttt{Files.copy()} method but it provides less control}\\\textsf{over the data flow.}

\textsf{Question - 2}

     \textsf{11 : System.getProperty("user.dir"), returns the current execution directory.}\\\textsf{18 - 20 : Converting the list into a stream and mapping it to an integer as }\\\textsf{\hspace{3.8em} total words in the current line and finally returning the total number}\\\textsf{\hspace{3.8em}  of  words.}

\textsf{\textit{Skipped some optimizations and obvious notations for increasing readability.}}

Attachments:
Answered by Anonymous
6

Answer:

1-import java.io.*;

import java.util.*;

class Copyfile {

public static void main(String arg[]) throws Exception {

Scanner sc = new Scanner(System.in);

System.out.print("Provide source file name :");

String sfile = sc.next();

System.out.print("Provide destination file name

Explanation:

hope it helps to u

Similar questions