Commit a3b6328b by Patryk Czarnik

katalog out

parent b4f408b9
......@@ -8,7 +8,7 @@ public class Zapis1 {
public static void main(String[] args) {
System.out.println("Start");
try {
PrintWriter out = new PrintWriter("nowy1.txt");
PrintWriter out = new PrintWriter("out/nowy1.txt");
out.println("Pierwsza linia");
out.println("Druga linia");
out.println("Czas modyfikacji: " + LocalTime.now());
......
......@@ -11,7 +11,7 @@ public class Zapis2 {
// ostatnia cyfra sekundy
int cyfra = now.getSecond() % 10;
try {
PrintWriter out = new PrintWriter("nowy2.txt");
PrintWriter out = new PrintWriter("out/nowy2.txt");
out.println("Pierwsza linia");
out.println("Druga linia");
out.println("Czas modyfikacji: " + now);
......
......@@ -12,7 +12,7 @@ public class Zapis3_Try_With_Resources {
int cyfra = now.getSecond() % 10;
// Od Java 7 mamy konstrukcję "try-with-resources"
// w momencie wychodzenia z tego bloku (ale także w sposób wyjątkowy) na obiekcie out zostanie wywołane close
try(PrintWriter out = new PrintWriter("nowy3.txt")) {
try(PrintWriter out = new PrintWriter("out/nowy3.txt")) {
out.println("Pierwsza linia");
out.println("Druga linia");
out.println("Czas modyfikacji: " + now);
......
......@@ -14,7 +14,7 @@ public class Zapis4_Try_Finally {
// można użyć sekcji finally w taki sposób:
PrintWriter out = null;
try {
out = new PrintWriter("nowy4.txt");
out = new PrintWriter("out/nowy4.txt");
out.println("Pierwsza linia");
out.println("Druga linia");
out.println("Czas modyfikacji: " + now);
......
......@@ -8,7 +8,7 @@ public class ZapisLiczb1 {
public static void main(String[] args) {
System.out.println("Start");
try {
PrintWriter out = new PrintWriter("liczby1.txt");
PrintWriter out = new PrintWriter("out/liczby1.txt");
for(int i = 1; i <= 10_000; i++) {
out.println(i);
// operacja flush wymusiłaby fizyczny zapis w pliku tym momencie - ale to zmniejsza wydajność
......
package p16_pliki;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class ZapisLiczb3 {
public static void main(String[] args) {
System.out.println("Start");
try(PrintWriter out = new PrintWriter("out/liczby3.txt")) {
for (int i = 1; i <= 10_000; i++) {
out.println(i);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
System.out.println("Koniec");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment