Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need Help with storing text to a file!

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help with storing text to a file!

    1 Prompt the user for the name of the file to read.
    2 Reads file
    3 Write the non-comma characters to output.txt, including all spaces.
    4 When done reading the input file, write the total number of comma’s removed to the console window.

    So far I believe that I have accomplished the first two objectives with the code I have, now I just need help figuring 3 & 4.


    Scanner k = new Scanner (System.in);
    System.out.println("Enter input file name");
    String inputFile = k.nextLine();

    System.out.println("Enter output file name");
    String outputFile = k.nextLine();

    File input = new File(inputFile);
    Scanner s = new Scanner (input);

    FileWriter output = new FileWriter(outputFile, true);
    PrintWriter outputFile = new PrintWriter (output );

    while(s.hasNext());
    {
    String line = s.nextLine();

    outputFile.println(line);
    }
    outputFile.close();
    s.close();
    }

    }

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    279
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Need Help with storing text to a file!

    This link can help to solve no 3
    https://stackoverflow.com/a/1994281
    Whatever you are, be a good one

Similar Threads

  1. Java code Split text file into multiple text file
    By jayraj in forum What's Wrong With My Code?
    Replies: 26
    Last Post: April 19th, 2013, 06:14 AM
  2. HELP with reading a clients ip address and storing in a text file.
    By dannyyy in forum Java Theory & Questions
    Replies: 1
    Last Post: April 4th, 2011, 07:20 AM
  3. [SOLVED] Storing info into a text file & adding to it
    By BlackFlame in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2011, 09:06 PM
  4. [SOLVED] Reading from a text file and storing in arrayList
    By nynamyna in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 26th, 2010, 09:55 PM
  5. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM

Tags for this Thread