Answer:
import java.io.IOException;
import java.io.PrintWriter;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
public class WriteFile {
public static boolean s2f(String fileName,String content)
{
boolean result = true;
if(content == null || fileName == null)
result = false;
else
{
try{
PrintWriter fileWriter = new PrintWriter(fileName, "UTF-8");
fileWriter.println(content);
fileWriter.close();
} catch (IOException e) {
result = false;
}
}
return result;
}
public static void main(String[] args)
{
boolean res = s2f("data.txt","Java is awesome.");
if(res==true)
System.out.println("Successful");
else
System.out.println("There was some error in writing to a file.");
}
}