Results 1 to 2 of 2
  1. #1
    kalanidhi is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Angry How to edit/delete a line in *.dat file in java io and applets

    Hai every body
    This is Kalanidhi
    I hav a problem in editing and deleting line by line of a *.dat file
    Here i am using trainee details which are to be updated.
    I successfully added and viewed trainee details.
    Would u pls kindly help me out in sorting the problem

    Here I am pasting the code i hav successfully done.

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;
    import java.io.RandomAccessFile;
    import java.util.ArrayList;
    import java.util.StringTokenizer;

    public class ReadWriteFile {
    String id=null;
    String name=null;
    String dept=null;
    String doj=null;
    String adrss=null;

    public void WriteFile(String Id,String Name,String Dept,String Doj,String Adrss) throws IOException{

    File f=new File("TraineeDetails.dat");
    if(!f.exists()){
    f.createNewFile();
    }
    BufferedWriter bw=new BufferedWriter(new FileWriter("TraineeDetails.dat",true));
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter Id : ");
    Id=br.readLine();
    System.out.print("Enter name : ");
    Name=br.readLine();
    System.out.print("Enter dept : ");
    Dept=br.readLine();
    System.out.print("Enter doj : ");
    Doj=br.readLine();
    System.out.print("Enter adrss : ");
    Adrss=br.readLine();
    bw.write(Id+"::"+Name+"::"+Dept+"::"+Doj+"::"+Adrs s+":END:");
    bw.flush();
    bw.newLine();
    bw.close();


    }

    public static void main(String[] args) throws IOException {
    ReadWriteFile rwf=new ReadWriteFile();
    String TID = null;
    String TADRSS = null;
    String TDOJ = null;
    String TNAME = null;
    String TDEPT = null;
    rwf.ReadFile(TID,TNAME,TDEPT,TDOJ,TADRSS);

    }
    public void ReadFile(String Id1,String Name1,String Dept1,String Doj1,String Adrss1){

    try{
    // Open the file that is the first
    // command line parameter
    FileInputStream fstream = new FileInputStream("TraineeDetails.dat");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) != null) {
    // Print the content on the console
    System.out.println (strLine);
    }
    //Close the input stream
    in.close();
    }catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }
    }
    }

    if u hav any suggetions pls post them here
    Last edited by kalanidhi; 11-10-2008 at 09:54 AM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    No one wants to here solve your question and mail it to you. If you want to find the solution hang on here and deal with other members. Lots of members are ready to help here, but not in this way.

Similar Threads

  1. [SOLVED] Delete Current line from file
    By Azndaddy in forum New To Java
    Replies: 2
    Last Post: 04-06-2012, 08:00 AM
  2. Replies: 1
    Last Post: 10-16-2008, 09:56 PM
  3. Replies: 3
    Last Post: 12-26-2007, 06:42 AM
  4. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 AM
  5. Doubt in edit and delete methods
    By ai_2007 in forum Advanced Java
    Replies: 3
    Last Post: 07-01-2007, 11:40 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
  •