Testing_.java
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.Scanner;
public class Testing_
{
public static void main(String args[]) throws FileNotFoundException{
System.out.print("Enter string to be written to file: ");
//input
Scanner scanner = new Scanner(System.in);
String stringToBeWritten = scanner.nextLine();
Formatter formatter = new Formatter("myFile.txt");
formatter.format("THe string I want to write is: %s", stringToBeWritten);
if (formatter!=null)
formatter.close();
System.out.println("Written!");
}
}
No comments:
Post a Comment