Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So i wrote a code to create a temporary file with a specific name and with the .txt extension

Java
File f=File.createTempFile("LoginStatus",".txt",new File("/Users/Alex/Desktop"));


I went to check out the file. I see that after the prefix it has a random series of numbers, followed by the file extension..

Could someone please help :)

*Take note, i'm not a professional, so please bear the pain of making it as simple as possible

Thanks :)
Posted

1 solution

That's a temporary file, that one is supposed to be unique named and is just for temporary use - normally less then an application's life cycle.

You want to hold some "LoginStatus". What does that mean? what is in there?

I would recommend to make a facade for that or to store the data in a property list.
Both will be destroyed when the application is ending, data must not be written to disc, so it's pretty safe.

But please tell us what you want to store.

Simple Code:
The application holds a Hashmap, which stores the current status, set as a enum to make it easy & safe for setting.

This is very basic, for more information I'd recommend to create an Object holding one employee's data in a facade.
Java
import java.util.HashMap;

public class Application {
	public enum STATUS {
		IN, OUT
	}
	private HashMap<String, STATUS> oMap = new HashMap<String, STATUS>();

	public Application(){
		setStatus("Alex", STATUS.IN);
		setStatus("John", STATUS.IN);
		setStatus("Jack", STATUS.IN);
		
		showStatus();
		// change
		setStatus("Alex", STATUS.OUT);
		
		showStatus();
	}
	
	private void showStatus() {
		for (String strValue : oMap.keySet()) { 
			System.out.println("The Employee " + strValue + " is " + oMap.get(strValue));
		}
		System.out.println(); // empty line for better reading
	}

	// status is updated or added automatically to the map
	private void setStatus(String strName, STATUS oState){
		oMap.put(strName, oState);
	}

	public static void main(String[] args) {
		// start app
		Application oApp = new Application();
	}
}
 
Share this answer
 
v2
Comments
Umar2 4-Oct-12 14:50pm    
I want to store the login status of employees.. Say for example i log into the system then it will read "Alex=IN"
TorstenH. 4-Oct-12 14:57pm    
Just if someone is in or a log with time of login, time of logout, calculated work time, ...?
This can get a bit complex, I recommend to first just hold a status.
I will update my answer to give you a short code for a jump start.
Umar2 4-Oct-12 15:14pm    
No dont worry about that, i found another method of doing it
TorstenH. 4-Oct-12 15:19pm    
?? what "method of doing it" ??

Check the simple code above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900