blob: 179e678ea9b918905da4d80133967a7f223eca9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import java.io.FileWriter;
import java.io.IOException;
public class Main {
static void writeLines(String name) throws IOException{
FileWriter f = null;
try {
f = new FileWriter(name);
for (int i = 1; i <= 100; i++) {
f.write(String.format("%-3d ", i));
if (i % 10 == 0) {
f.write(System.lineSeparator());
}
}
} finally {
if (f != null) {
f.close();
}
}
}
public static void main(String[] args) {
String name = "hej.txt";
if (args.length > 0) {
name = args[0];
}
System.out.printf("Writing to %s%n", name);
try {
writeLines(name);
} catch(IOException e) {
System.err.printf("Failed with: %s%n", e);
}
}
}
|