| | |
dont know how to delete string..help!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2008
Posts: 4
Reputation:
Solved Threads: 0
pls help!! can u give me some tips how to delete a string or list in a textfile based on this code....i created this code but i dont know how to delete it..pls explain in simple english because im not American.....
tnx a lot...ur response is very much appreciated... =)
tnx a lot...ur response is very much appreciated... =) Java Syntax (Toggle Plain Text)
import java.io.*; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class TextFile { public static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); public static String[] person; public static String[] tempPerson; public static String[] sepTemp; public static int xCtr; public static void mainMenu() { System.out.println("1] Insert"); System.out.println("2] Delete"); //////////////// System.out.println("3] Exit");/////////////// } public static void insertData() throws IOException ///insert { System.out.print("Enter name: "); String pName = stdin.readLine(); String temp; if (xCtr != 0) { temp =tempPerson[0] + ", " + pName; } else { temp = pName; xCtr = 1; } FileOutputStream x = new FileOutputStream("myTextFile.dat"); ObjectOutputStream y = new ObjectOutputStream(x); y.writeObject(new String[] {temp}); System.out.println("New Entry Updated..."); y.close(); } public static void displayInitData() //displayInitial data { try { FileInputStream x = new FileInputStream("myTextFile.dat"); ObjectInputStream y = new ObjectInputStream(x); tempPerson = (String[])(y.readObject()); sepTemp = new String[100000]; sepTemp = tempPerson[0].split(", "); int i = 0; do { person[i] = sepTemp[i]; i = i + 1; } while(i<sepTemp.length); xCtr = i; } catch(Exception m) { m.getMessage(); } } public static void displayData() //display data { int i=0; do { System.out.println(sepTemp[i]); i = i + 1; } while(i<sepTemp.length); } public static void main (String[] args) throws IOException, Exception { int choiceMenu; person = new String[100000]; tempPerson = new String[100000]; displayInitData(); do { mainMenu(); System.out.print("Enter Choice: "); choiceMenu = Integer.parseInt(stdin.readLine()); switch(choiceMenu) { case 1: displayInitData(); insertData(); break; case 2:delete(); break; case 3: if (xCtr > 0) { displayInitData(); displayData(); } else System.out.println("No Record"); break; default: } } while(choiceMenu!=3); } }
Read the file and write a new file leaving out the pieces that should be "deleted". Then delete the original file and rename the newfile to the the name the oldfile had.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
The same, of course, except that you modify what should be modified before writing it to the new file.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- SQL Injection Attack (Database Design)
- Problem of abruptly termination... (C++)
- Stack in C (C)
- Creating a Basic String Database (C++)
- Simply question: How do I return a string from a function (C)
- Delete from a listbox (Visual Basic 4 / 5 / 6)
- log in script saves cookie (JavaScript / DHTML / AJAX)
- Problem of sorting words of each string using pointers (C++)
- httpd setup problem (*nix Software)
Other Threads in the Java Forum
- Previous Thread: How to set System Date & time
- Next Thread: Java GUI problem - "BeanBox" swing component implementation
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database db defaultmethod development dice dragging draw ebook eclipse error event exception formatingtextintooltipjava fractal game givemetehcodez graphics gui html ide image infinite input integer invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx oracle parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






