Results 1 to 3 of 3
  1. #1
    misterwebb is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default Adding line numbers to code in output file

    okay so here is my problem:
    The program should ask the user for input and output file names. The program should read the input file, add line numbers and write the result to the output file. Set a field width for the line number to 5. The line number should be followed by a semicolon and a space.

    Okay so far i think i need to have a scanner get the input from the user of the file name and import a and check for the files existence using
    file file = new file("FilesName");
    then an if statement

    then open the file using the scanner.

    Now this is where my problem begins more than before, i dont know how i would go about placing the numbers in the code and placing it in an output file?

  2. #2
    misterwebb is offline Member
    Join Date
    Feb 2011
    Rep Power


    Okay so i think i need to read from the input file, save what it reads to a variable, prefix it with linenum ":", put back into output file. and use printwriter?

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power


    Java Code:
    loop while input file has more input {
        read line from input file (depending upon how you do this it might be part of the loop condition)
        write line number to ouput file
        update line number
        write line to output file
    It is not that hard as long as you set up your two streams properly.

Similar Threads

  1. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  2. formatting numbers in output
    By andy3 in forum New To Java
    Replies: 3
    Last Post: 05-27-2010, 06:43 PM
  3. Replies: 3
    Last Post: 02-16-2009, 09:20 PM
  4. Replies: 7
    Last Post: 11-19-2008, 02:09 PM
  5. Adding numbers in array
    By Shaolin in forum New To Java
    Replies: 1
    Last Post: 11-15-2007, 06:30 PM

Posting Permissions

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