101k views
2 votes
Define a public static method named s2f that takes two String arguments, the name of a file and some text. The method creates the file and writes the text to it. If all goes well the method returns true. If, however, either of its arguments are null or if there is any problem in creating or writin

1 Answer

2 votes

Answer:

Java solution (because only major programming language that has public static methods)

(import java.io.* before hand)

public static boolean s2f(String fileName, String text){

try{

PrintWriter out = new PrintWriter(new File(fileName));

out.println(text);

out.close();

return true;

}

catch(Exception e){

return false;

}

}

User Babboon
by
5.4k points