Welcome to Dream.In.Code
Become a Java Expert!

Join 150,404 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 931 people online right now. Registration is fast and FREE... Join Now!




i dont know how to delete and update the textfile

 
Reply to this topicStart new topic

i dont know how to delete and update the textfile

Syntax Error
17 Mar, 2008 - 01:55 AM
Post #1

New D.I.C Head
*

Joined: 11 Mar, 2008
Posts: 3

pls help!! can u give me some tips how to delete a string or list in a textfile and to update it 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..... biggrin.gif tnx a lot...ur response is very much appreciated... =)

CODE

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: update();break;
case 4:
                        if (xCtr > 0)
                        {
                            displayInitData();
                            displayData();
                        }
                        else
                            System.out.println("No Record");
                        break;
                default:
            }
        }
        while(choiceMenu!=3);
        
    }
}


This post has been edited by Syntax Error: 17 Mar, 2008 - 03:08 AM
User is offlineProfile CardPM
+Quote Post

fsloke
RE: I Dont Know How To Delete And Update The Textfile
17 Mar, 2008 - 10:40 PM
Post #2

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
Please kindly refer to my post
http://www.dreamincode.net/forums/showtopic46473.htm


To delete a File
File a = new File("location of your file");
a.delete();
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:21PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month