Thursday, 23 July 2015

write a Java code to Generate Random 10,000 numbers and store into csv file.



        // TODO add your handling code here:
        try
        {
        Random r = new Random();
        //System.out.println("Numbers are");
      File file = new File("D:/p1.csv");
     
      FileWriter writer = new FileWriter(file);
    
      System.out.println("start");
        for(int i=1;i<=100;i++)
        {
            for(int j=1;j<=100;j++)
            {
                int value;
                value=r.nextInt(10000);
                writer.append(Integer.toString(value));
                writer.append('\n');
            }
           
        }
        writer.flush();
        writer.close();
        System.out.println("end");
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }  

1 comment: