Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java file
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 Smile | :)
 
*Take note, i'm not a professional, so please bear the pain of making it as simple as possible
 
Thanks Smile | :)
Posted 4-Oct-12 7:47am
Umar2291

1 solution

Rate this: bad
good
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 {
		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();
	}
}
  Permalink  
v2
Comments
Umar2 at 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. at 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 at 4-Oct-12 15:14pm
   
No dont worry about that, i found another method of doing it
TorstenH. at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
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