4 Replies - 207 Views - Last Post: 30 January 2018 - 05:37 AM Rate Topic: -----

#1 Abhavya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 21-January 18

Sorting a text file from CommandLine

Posted 29 January 2018 - 05:57 PM

Write a java program that takes several command line parameters.The first parameter should be interpreted as the name of the source file and the second as the name of the target file and then any parameters after that should be integers and will be interpreted as set of indices.the program should create a new target file with a specified name and it should then copy from the source file the line numbers indicated by the indices provided on the command line.
I am very confused on where to begin with and how to go about with the question.I only want to know the steps.

Is This A Good Question/Topic? 0
  • +

Replies To: Sorting a text file from CommandLine

#2 NormR  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 657
  • View blog
  • Posts: 4,961
  • Joined: 25-December 13

Re: Sorting a text file from CommandLine

Posted 29 January 2018 - 06:17 PM

Which parts of the assignment are you having problems with?
Do you know how commandline args are passed to the main method via its parameter of a String array?
Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon


Reputation: 7051
  • View blog
  • Posts: 14,732
  • Joined: 16-October 07

Re: Sorting a text file from CommandLine

Posted 30 January 2018 - 05:04 AM

You have two distinct problems. One, doing the actual work of sorting a source file and producing output. Two, getting the values for that work from the command line.

A reasonable start would be:
class Assignment {
    // The first parameter should be interpreted as the name of the source file
    // the second as the name of the target file
    // then any parameters after that should be integers and will be interpreted as set of indices.
    private static void sortFile(String srcFileName, String dstFileName, int [] indices) {
        // your code here
    }

    // Write a java program that takes several command line parameters.
    // see args?  These are command line parameters
    public static void main(String[] args) {
        // just to get an idea what you're looking at
        // you might consider printing out args

        // check to see if you have enough args
        // fail if you don't

        String srcFileName = // your code here
        String dstFileName =  // your code here
        int [] indices = new int[/* your code here*/];
        // you'll need to do a little more to get those indices, of course, here

        // then, ultimately, call sortFile with the args given
        sortFile(srcFileName, dstFileName, indices);
    }
}



Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3503
  • View blog
  • Posts: 15,834
  • Joined: 20-September 08

Re: Sorting a text file from CommandLine

Posted 30 January 2018 - 05:26 AM

There nothing actually about sorting in the assignment spec
Was This Post Helpful? 1
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon


Reputation: 7051
  • View blog
  • Posts: 14,732
  • Joined: 16-October 07

Re: Sorting a text file from CommandLine

Posted 30 January 2018 - 05:37 AM

@g00se: Nice catch.

Please change the code I offered from sortFile to transferFile and carry.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1