Results 1 to 2 of 2
Thread: delete a field program
- 04-03-2011, 03:30 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 56
- Rep Power
- 0
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.
Kind regardsJava 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
Shyam :) Please help
I dont know how to declare variables whether they should be public or whateverLast edited by Shyamz1; 04-03-2011 at 04:33 PM.
- 04-03-2011, 04:24 PM #2
Senior Member
- Join Date
- Nov 2010
- Location
- Delhi
- Posts
- 135
- Blog Entries
- 1
- Rep Power
- 0
Similar Threads
-
front end display of field description when clicking the field name
By neils in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 10-29-2010, 11:47 AM -
Trigger cmd to delete a file in java program
By hari.kr in forum Advanced JavaReplies: 4Last Post: 04-28-2010, 07:37 PM -
how from an Access Currency field I populate a hidden field
By lse123 in forum Java ServletReplies: 4Last Post: 01-17-2010, 11:13 PM -
How to delete a JLabel by using the keyboard 'delete' key?
By Suren in forum AWT / SwingReplies: 2Last Post: 04-20-2009, 08:00 AM -
Error: Cannot delete a.txt:It is being used by another person or program
By trill in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 07:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks