generate random number of string with java

i want to generate around 10000 lines of random strings and input it to file in java. Please tell me how to do it. Also tell me how to reach to the end of this file after generating the lines. Also tell me how to find the length of the file and the number of lines in this file. Please do not use any system commands or tail command
Who is Participating?
sundar62Connect With a Mentor Commented:
Please find the code snippet below to generate the random number. you can get the number of lines of the file from the attached link -

You may modify the code accordingly..
public class GUID {
   private static SecureRandom s_secureRandom = new SecureRandom();
   public static void main(String[] args) throws Exception {
	   File file = new File("write.txt");
	   PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file)));
	   for (int i = 0; i < 10000 ;i++ )
	   System.out.println("Your file has been written");
    * generate guid from time,addr,hash and rand
   public static String generate() {
      StringBuilder stringBuilder = new StringBuilder();
      int time = (int) System.currentTimeMillis();
      int rand = s_secureRandom.nextInt();
      return stringBuilder.toString();
    * get int as 8-char string
   private static String hexFormat(int data) {
      StringBuilder stringBuilder = new StringBuilder();
      return stringBuilder.substring(stringBuilder.length() - 8);

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.