Can someone help me to write a program that can read and write to a file and then store the user input in the file using the Property and ClassLoader classes.Also when another person uses the program it should tell you the last person to use the program.Thanks in advance

Show us what you have.

import java.io.*;
import java.io.File;
import java.util.*;
public class FileReadWrite{

    public static void main(String[] args) throws IOException{

     BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
      String name = " "; 

      FileWriter fw = new FileWriter("myFile.properties");//append the file content
      BufferedWriter bw = new BufferedWriter(fw);
      bw.write("Peter maingi"+"\n"); 
      bw.write(name);
      bw.close();
      fw.close();

    //create property object
      Properties props = new Properties();

      InputStream inputStream = ClassLoader.getSystemResourceAsStream("myFile.properties");
      props.load(inputStream);
      String myValue = props.getProperty("key");
      //props.store();

      FileReader fr=new FileReader("myFile.properties");
      BufferedReader br = new BufferedReader(fr);

       System.out.println("Welcome,the name of the last person to use the program was:" + br.readLine());

        while ((name = br.readLine()) != null) { 
            System.out.println("Enter your Name");
            name = stdin.readLine();
           //System.out.println(name);
        }

      br.close();
      fr.close();
  }
}

Rather than having both properties and an extra line with a username, simply add a user=name property. Then all you have to do is load, setProperty (for each key to be changed), and store.

I appreciated for ur assistance.The program finnally did wonders.Kudos for ur gud work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.