Click here to Skip to main content
13,050,617 members (84,304 online)
Rate this:
Please Sign up or sign in to vote.
See more:
So i wrote a code to create a temporary file with a specific name and with the .txt extension

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 4-Oct-12 7:47am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
import java.util.HashMap;
public class Application {
	public enum STATUS {
	private HashMap<String, STATUS> oMap = new HashMap<String, STATUS>();
	public Application(){
		setStatus("Alex", STATUS.IN);
		setStatus("John", STATUS.IN);
		setStatus("Jack", STATUS.IN);
		// change
		setStatus("Alex", STATUS.OUT);
	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();
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100