import java.io.*;
import java.util.Random;
public class myfile
{
public static void main(String[] args) throws IOException
{
int count=1;
while(count<=100)
{
Random r=new Random();
int myrannum=r.nextInt(10000);
File f=new File("c:/raj/file"+myrannum+".txt");
if(!f.exists())
{
f.createNewFile();
FileWriter fw = new FileWriter(f);
BufferedWriter out = new BufferedWriter(fw);
out.write("Hai How are you ?");
out.close();
System.out.println("File Path : "+f.getPath());
System.out.println("Total Disk size : "+(((f.getTotalSpace()/1024)/1024)/1024)+" GB");
count++;
}
else
{
System.out.println("File"+myrannum+".txt is already exist");
}
}
}
}
Output:
File Path : c:\raj\file4851.txt
Total Disk size : 232 GB
File Path : c:\raj\file4164.txt
Total Disk size : 232 GB
File Path : c:\raj\file8551.txt
Total Disk size : 232 GB
No comments:
Post a Comment