achatburn
asked on
Writing a unique ID to a text file.
Hi Experts,
I am trying to write to a text file on the server. The twist is I need a unique ID at the start of every input. I am not sure how create a unique ID. Can you help. This what I have so far.
BufferedWriter fp = null;
String str = new String("blah blah; sdfg; dsfg; dsfg");
try {
fp = new BufferedWriter(new FileWriter("./webapps/prin tTest/text TempText.t xt", true));
fp.write(str, 0, str.length());
fp.newLine();
fp.flush();
fp.close();
}
catch (IOException e) {
}
I am trying to write to a text file on the server. The twist is I need a unique ID at the start of every input. I am not sure how create a unique ID. Can you help. This what I have so far.
BufferedWriter fp = null;
String str = new String("blah blah; sdfg; dsfg; dsfg");
try {
fp = new BufferedWriter(new FileWriter("./webapps/prin
fp.write(str, 0, str.length());
fp.newLine();
fp.flush();
fp.close();
}
catch (IOException e) {
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Get from javadocs,
A UID instance contains three primitive values:
* unique, an int that uniquely identifies the VM that this UID was generated in, with respect to its host and at the time represented by the time value (an example implementation of the unique value would be a process identifier), or zero for a well-known UID
* time, a long equal to a time (as returned by System.currentTimeMillis() ) at which the VM that this UID was generated in was alive, or zero for a well-known UID
* count, a short to distinguish UIDs generated in the same VM with the same time value
If you would like to know how does he generate those values, you can check the source.
A UID instance contains three primitive values:
* unique, an int that uniquely identifies the VM that this UID was generated in, with respect to its host and at the time represented by the time value (an example implementation of the unique value would be a process identifier), or zero for a well-known UID
* time, a long equal to a time (as returned by System.currentTimeMillis()
* count, a short to distinguish UIDs generated in the same VM with the same time value
If you would like to know how does he generate those values, you can check the source.
ASKER
You Rock
Thanks
Thanks
ASKER
This returns this 18e18a3:f880eeed24:-7fd6. I am a beginning JSP programmer. I would like to know how this works. I will give you a hundred more point if you briefly explain this.