1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
makkiz [27]
3 years ago
10

Write an application that determines which, if any, of the following files are stored in the folder where you have saved the exe

rcises created in this chapter: autoexec.bat, CompareFolders.java, FileStatistics.class, and Hello.doc. The program should display the number of files found. For example, if two of the files are found display the message 2 of the files exist.
Computers and Technology
1 answer:
Elza [17]3 years ago
8 0

Answer:

Here is the JAVA application that determines which if any of the following files are stored in folder where you have saved the exercises created.

import java.nio.file.*;   // used to manipulate files and directories

import java.nio.file.attribute.*;  //used to provide access to file and file attributes

import static java.nio.file.AccessMode.*;  // provides access modes to test the accessibility of a file

import java.io.IOException;  //for exception handling

class FindSelectedFiles {

public static void main(String[] args) { //start of main function

   Path f1 = Paths.get("/root/sandbox/autoexec.bat"); //creates Path object f1 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   Path f2 = Paths.get("/root/sandbox/CompareFolders.java");  //creates Path object f2 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   Path f3 = Paths.get("/root/sandbox/FileStatistics.class");   //creates Path object f3 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   Path f4 = Paths.get("/root/sandbox/Hello.doc"); //creates Path object f4 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   int count=0; //used to count the number of files found  

try{  // used to define a code chunk to be tested for errors

 f1 = Paths.get("/root/sandbox/autoexec.bat");  // Converts a path string when joined form a path string to a Path

 System.out.println(f1);  //prints the file

     /* getFileSystem method is used to return the file system that created this Path object f1 and checkAccess Verifies access and throws exception if something is wrong

 f1.getFileSystem().provider().checkAccess(f1);  

 System.out.println(f1 +" File Exists\n");  //if file exists then displays this message

 count++;  }  //adds 1 to the count of number of files found

 catch (IOException e) {  //a code chunk to be executed if error occurs in the try part

  System.out.println("File Doesn't Exist\n"); }  //if file not found displays this message

   

try{  //works same as above try block but for 2nd folder and object f2

 f2 = Paths.get("/root/sandbox/CompareFolders.java");

 System.out.println(f2);

 f2.getFileSystem().provider().checkAccess(f2);

 System.out.println(f2 +" File Exists\n");

 count++;  }

 catch (IOException e) {

  System.out.println("File Doesn't Exist\n"); }

   

try{  //works same as above try block but for 3rd folder and object f3

 f3 = Paths.get("/root/sandbox/FileStatistics.class");

 System.out.println(f3);

 f3.getFileSystem().provider().checkAccess(f3);

 System.out.println("File Exists\n");

 count++; }

 catch (IOException e) {

  System.out.println("File Doesn't Exist\n"); }

   

try{  //works same as above try block but for 4th folder and object f4

    f4 = Paths.get("/root/sandbox/Hello.doc");

    System.out.println(f4);

 f4.getFileSystem().provider().checkAccess(f4);

 System.out.println(f4 +" File Exists\n");

 count++; }

 catch (IOException e) {

  System.out.println("File Doesn't Exist\n"); }

   

   System.out.println(count+" of the files exist");  }  } //displays the number of files found

Explanation:

If you want to directly pass the file name as argument to Paths.get() method then you can use the following code:

   Path f1 = Paths.get("autoexec.bat");

   Path f2 = Paths.get("CompareFolders.java");

   Path f3 = Paths.get("FileStatistics.class");

   Path f4 = Paths.get("Hello.doc");

The program determines if any, of the files from autoexec.bat, CompareFolders.java, FileStatistics.class, and Hello.doc. are stored in the folder. If a file is found then the program displays the message File exists and add 1 to the count variable each time a file is found. If all the files are found then the program returns the count as 4 otherwise the program display the number of files found by displaying the computed final value of count in the output. Lets say all the files are found then the output of the above program is:

autoexec.bat                                                                                                                                                   autoexec.bat File Exists  

                                                                                                                                                      CompareFolders.java                                                                                                                                            CompareFolders.java File Exists                                                      

                                                                                                                                                         FileStatistics.class                                                                                                                                           File Exists                                                                                        

                                                                                                                                                     Hello.doc                                                                                                                                                      Hello.doc File Exists  

   

4 of the files exist    

You might be interested in
Provide all resonance structures of the sigma complex when aniline reacts with an electrophile to yield the para-substituted pro
Nadya [2.5K]

Answer:

See attached picture.

Explanation:

See attached picture for detailed explanation.

3 0
3 years ago
Exporting data is sending data to a new file. true or false
dolphi86 [110]
False__________________________
8 0
3 years ago
Read 2 more answers
How are phishing, ransomware and distributed- denial of service attack alike and different?
Aleks04 [339]

Answer:

Phishing means cyber theft in which the cyber thief sends the target PC a malicious email, which looks like coming from some known source, and they ask for certain critical information, which must not be leaked. Similarly, In ransomware, they send the phishing email with malicious code, and they hack the computer system. They then ask for a ransom as a return for reactivating your PC. Distributed Denial of service attack happens when the traffic flood the bandwidth and the resources of a PC, and finally a lot of are denied of access to them. Ransomware, when it attacks a bank account, becomes a Denial of service attack, as multiple users are stopped from accessing their account. All of these are hence, almost the same and revolves around the phishing email.

Explanation:

Please check the answer.

8 0
2 years ago
IF a relation schema is in 3NF, it is in BCNF.true or falsa
likoan [24]

Answer:

It would be very false.

6 0
2 years ago
They have requested a 1- to 2-page memo that describes the hospital's protections against a ransomware attack.
olganol [36]
What is the memo that they have asked of you
3 0
3 years ago
Other questions:
  • what is happening when humans control the breeeding of living things to favor certain desired features
    9·1 answer
  • Which task manager tab provides details about how a program uses system resources?
    14·1 answer
  • What are features of a product?
    8·2 answers
  • An email message containing a warning related to a non-existent computer security threat, asking a user to delete system files f
    6·1 answer
  • What would you have to know about the pivot columns in an augmented matrix in order to know that the linear system is consistent
    13·1 answer
  • How many bits does it take to store a 3-minute song using an audio encoding method that samples at the rate of 40,000 bits/secon
    12·1 answer
  • PLEASE HELP THIS WAS DUE YESTERDAY AND I DIDN'T GET TO IT IN TIME!!!!!!
    8·1 answer
  • Difrent between computer and computer system​
    9·1 answer
  • You defined a shoe data type and created an instance.
    11·1 answer
  • How can we search person in brainly for sending request of friend
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!