I was searching for information on how to write text from Java to a file and I read this question
however, none of the answers included what needs to be imported to make PrintWriter
work.
QUESTION: What are the correct import statements for PrintWriter
? If this is NOT my issue, please tell me what the issue is and how to solve it.
PLEASE USE PLAIN ENGLISH!! I am amateur coder with zip experience, so explain this to me like you are talking to a 7th grader.
Here is my code:
import java.util.Random;
import java.util.*;
import java.lang.Object;
public class Driver01 {
public static void main(String[] args) {
PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");
for (int b = 1; b < 10001; b++) {
int x = (int) (Math.random() * 9);
int y = (int) (Math.random() * 9);
int z = (int) (Math.random() * 9);
int a = (int) (Math.random() * 9);
writer.print(b + ":" + x);
writer.print(y);
writer.print(z);
writer.print(a);
writer.println("");
writer.close();
}
}
}