Write the code that will create a file named test2txt that w

Write the code that will create a file named test2.txt, that will then put the string \'Xyz 200 .75\' into the file, that will then put the string \'Abc 1000 2.7\' into the file and will then close the file

Solution

WriteFile.java

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;


public class WriteFile {

  
   public static void main(String[] args) throws FileNotFoundException {
       File file = new File(\"test2.txt\");
       PrintStream ps = new PrintStream(file);
       ps.println(\"Xyz 200 .75\");
       ps.println(\"Abc 1000 2.7\");
       ps.flush();
       ps.close();
       System.out.println(\"File has been created.\");
   }

}

Output:

File has been created.

test2.txt

Xyz 200 .75

Abc 1000 2.7

Write the code that will create a file named test2.txt, that will then put the string \'Xyz 200 .75\' into the file, that will then put the string \'Abc 1000 2.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site