Ask Question

Define a public static method named f2s that takes a single String argument, the name of a file. The method returns a (concievably very large!) String that is an exact copy of the contents of the file. If the file cannot be opened the method returns null.

+2
Answers (1)
  1. 6 April, 14:52
    0
    public static String f2s (String s) throws IOException {

    File f = new File (s);

    Scanner input = new Scanner (f);

    String ss = "";

    while (input. hasNext ()) {

    ss + = input. nextLine ();

    }

    return ss;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Define a public static method named f2s that takes a single String argument, the name of a file. The method returns a (concievably very ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers