Results 1 to 2 of 2
  1. #1
    Shyamz1 is offline Member
    Join Date
    Oct 2010
    Posts
    56
    Rep Power
    0

    Default delete a field program

    Hi Guys how are you all?

    I'm trying to create a program which takes its input from standard input or a named file and puts its output on standard output or in another named file. I have the following code so far, any suggestions on what i'm doing wrong.

    Java Code:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    
    
    public class DeleteField 
    {
      public static void main(String args[]) 
      {
        // Divide the line into fields using tab as a delimiter
          String[] fields = inputLine.split("\t");
          String editedLine = "";
          if (fields.length < fieldToDelete)
            editedLine = inputLine;
          else
          {
            // We build the new line in parts
    	// Add the fields before the one to be deleted.
    	for (int index = 0; index < fieldToDelete - 1; index++)
    	  if (editedLine.equals("")) editedLine = fields[index];
    	  else                       editedLine += "\t" + fields[index];
    	// Add the fields after the one to be deleted.
    	for (int index = fieldToDelete; index < fields.length; index++)
    	  if (editedLine.equals("")) editedLine = fields[index];
    	  else			     editedLine += "\t" + fields[index];
          } // else
        
        try 
        {
          int delete = Integer.parseInt(args[0]); 
          // parsing delete
          BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
          PrintStream printStream = new PrintStream(System.out);
          String string = new String();
          while ((string = bufferRead.readLine()) != null) 
          { 
            // reads the line
            String fields[] = string.split("\t"); 
    	  // split the line
              for(int i=0;i < fields.length; i++) 
    	  {
                if ((i+1) != delete) 
    	    { 
    	      // if first number equals deleteField number avoid printing, otherwise, print
                  printStream.print(fields[i] + "\t");
                }
              }
    
              printStream.println();
    	  
          } // while
       } // try
       
       catch (IOException exception) 
       {
         System.out.println("Error!" + exception.getMessage());
       } // catch
       
       
     } // main
    } // class DeleteField
    Kind regards

    Shyam :) Please help

    I dont know how to declare variables whether they should be public or whatever
    Last edited by Shyamz1; 04-03-2011 at 04:33 PM.

  2. #2
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Smile

    I am pretty sure, You are not passing any argument to the program.

    Just check it!

Similar Threads

  1. front end display of field description when clicking the field name
    By neils in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-29-2010, 11:47 AM
  2. Trigger cmd to delete a file in java program
    By hari.kr in forum Advanced Java
    Replies: 4
    Last Post: 04-28-2010, 07:37 PM
  3. Replies: 4
    Last Post: 01-17-2010, 11:13 PM
  4. Replies: 2
    Last Post: 04-20-2009, 08:00 AM
  5. Replies: 1
    Last Post: 08-07-2007, 07:34 AM

Posting Permissions

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