Solved

Writing a unique ID to a text file.

Posted on 2003-10-27
4
198 Views
Last Modified: 2010-04-01
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/printTest/textTempText.txt", true));
     
         fp.write(str, 0, str.length());
         fp.newLine();
     
         fp.flush();
         fp.close();
   }
     catch (IOException e) {
     }
0
Comment
Question by:achatburn
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
kotan earned 400 total points
ID: 9631463
String str = new java.rmi.server.UID().toString();
0
 

Author Comment

by:achatburn
ID: 9631541
Hi Kotan,

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.
0
 
LVL 6

Expert Comment

by:kotan
ID: 9631572
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.
0
 

Author Comment

by:achatburn
ID: 9631608
You Rock

Thanks
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JSP Popup page 2 137
stateless EJB with glassfish 2 73
TreeSet comparator example 7 97
How to find missing packages when using Netbeans IDE 8.1 ? 19 59
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question