Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. redirecting and piping

redirecting and piping

Scheduled Pinned Locked Moved Java
java
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shekarchee
    wrote on last edited by
    #1

    How is the text file below (% java BinarySearch largeW.txt < largeT.txt) read as "args[0]". Code snippet would be apprecated

    public static void main(String[] args)
    {
    int[] whitelist = In.readInts(args[0]);
    Arrays.sort(whitelist);
    while (!StdIn.isEmpty())
    {
    int key = StdIn.readInt();
    if (rank(key, whitelist) == -1)
    StdOut.println(key);
    }
    }

    % java BinarySearch largeW.txt < largeT.txt 499569 984875 ...

    L 1 Reply Last reply
    0
    • S shekarchee

      How is the text file below (% java BinarySearch largeW.txt < largeT.txt) read as "args[0]". Code snippet would be apprecated

      public static void main(String[] args)
      {
      int[] whitelist = In.readInts(args[0]);
      Arrays.sort(whitelist);
      while (!StdIn.isEmpty())
      {
      int key = StdIn.readInt();
      if (rank(key, whitelist) == -1)
      StdOut.println(key);
      }
      }

      % java BinarySearch largeW.txt < largeT.txt 499569 984875 ...

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      args[0] is the file largeW.txt, while largeT.txt will be piped direct into the program as StdIn. I'm not sure what code snippet we can offer since the snippet above explains it so succinctly.

      Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

      S 1 Reply Last reply
      0
      • L Lost User

        args[0] is the file largeW.txt, while largeT.txt will be piped direct into the program as StdIn. I'm not sure what code snippet we can offer since the snippet above explains it so succinctly.

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        S Offline
        S Offline
        shekarchee
        wrote on last edited by
        #3

        My question is: How is arg[0] pointing to the text file? Code Snippet would be appreciated

        L 1 Reply Last reply
        0
        • S shekarchee

          My question is: How is arg[0] pointing to the text file? Code Snippet would be appreciated

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You have the code snippet, look at the definition of main. The args parameter is set by the framework as an array of strings which correspond to the parameters on the command line.

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups