Source Code : Printing Numbers to a Text File
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Printing Numbers to a Text File
import java.io.FileWriter;
import java.io.PrintWriter;
public class PrintWriterDemo {
public static void main() throws Exception{
PrintWriter pw = new PrintWriter(new FileWriter("dice.txt"));
for (int i = 1; i <= 1000; i++) {
int die = (int) (1 + 6 * Math.random());
pw.print(die);
pw.print();
if (i % 20 == 0)
pw.println();
}
pw.println();
pw.close(); // Without this, the output file may be empty
}
}
Thank with us