Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: i dont know where the problem is...help me here

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    8
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question i dont know where the problem is...help me here

    I tried to create a text file named Employee.txt. It holds the details of the employees including their Employee ID, name, designation, department, address, and phone number. The text file contains the following code:
    import java.io.*;

    public class EmpDetails
    {
    public static void main(String args[])
    {
    RandomAccessFile file=null;
    try
    {
    /* Opens the file in read/write mode */
    file=new RandomAccessFile("Employee.txt","rw");
    //code to write data to the file
    String s = "Employee ID " + “E001”+ " Employee Name" +”Steve” +"Designation" +”Accountant”;
    file.seek(file.length());
    file.writeBytes(s);
    file.close();
    } catch(IOException e)
    {
    System.out.println("Exception: " +e);
    }


    The entries are not stored permanently to the storage device. What is the might be problem with the preceding code?


  2. #2
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: i dont know where the problem is...help me here


  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    8
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i dont know where the problem is...help me here

    I try to go through them but still I cant see where I have gone wrong.. help please!!

  4. #4
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: i dont know where the problem is...help me here

    Have you got any errors because in my machine your code is working fine.
    It creates a text file with title "Employee.txt" and write the data in that file.

  5. #5
    Junior Member
    Join Date
    May 2014
    Posts
    8
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i dont know where the problem is...help me here

    no the code is right..the problem i'm facing is that "data written in Employee.txt is not stored permanently..." I want it to be stored permanent..how can I so it?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: i dont know where the problem is...help me here

    I want it to be stored permanent
    Nothing written to a disk file is permanent. It can be overwritten or deleted.
    Please explain what you mean by "permanent".
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: i dont know where the problem is...help me here

    what do you mean by
    data written in Employee.txt is not stored permanently...

Similar Threads

  1. dont know how to describe the problem.
    By arqdia in forum Loops & Control Statements
    Replies: 3
    Last Post: March 10th, 2014, 01:05 AM
  2. Problem with import java.util.*; dont know whats wrong
    By TheLeader in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 3rd, 2012, 12:33 PM
  3. Dont know how to recorrect
    By Asin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 2nd, 2011, 12:59 PM
  4. I dont get it....please help
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: June 30th, 2010, 03:16 AM
  5. Dont laugh at me
    By Neblin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2009, 08:18 AM