Results 1 to 2 of 2
  1. #1
    ATB
    ATB is offline Member
    Join Date
    Mar 2014
    Posts
    6
    Rep Power
    0

    Default create new file, ask user to write in it, save finally print content of file

    1. creates a file.
    2. ask user to write into that file
    3. save the file
    4. print content of file.

    is my current exercise
    so far i have gotten the code to create a file, and ask the user to input their age

    what should i use to save what the user writes into the file?

    Java Code:
    package assignment7;
     
    import java.io.*;
    import java.util.*;
    public class Exercise2 
    {
    	public static void main  ( String [  ]  args )  throws IOException
        {  
    		Scanner scan = new Scanner(System.in);
     
     
    		File f;
    		 f=new File("myfile.txt");
     
    		 if(!f.exists());
    		  {
    			  f.createNewFile();
    			  System.out.println("New file \"myfile.txt\" has been created to the current directory.");
    		  }
        	System.out.print("Enter your age as an integer: ");
        	int age = scan.nextInt();
     
        	System.out.println("Your age is " + age);
        }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default Re: create new file, ask user to write in it, save finally print content of file

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: 05-04-2012, 03:09 PM
  2. how to write URL content to a file
    By trkece in forum JDBC
    Replies: 3
    Last Post: 02-22-2011, 05:14 PM
  3. Replies: 7
    Last Post: 08-17-2010, 06:00 PM
  4. Replies: 10
    Last Post: 05-24-2010, 08:25 PM
  5. Replies: 0
    Last Post: 11-07-2008, 01:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •