Commit d0b48436 by Patryk Czarnik

porządki poranne

parent ad8a9b89
...@@ -31,9 +31,10 @@ public class Zamykanie { ...@@ -31,9 +31,10 @@ public class Zamykanie {
System.out.println("____\npróba 3:"); System.out.println("____\npróba 3:");
Stream<String> stream3 = lista.stream() Stream<String> stream3 = lista.stream()
.map(String::toUpperCase)
.onClose(() -> System.out.println("zamykanie 3a")) .onClose(() -> System.out.println("zamykanie 3a"))
.onClose(() -> System.out.println("zamykanie 3b")); .map(String::toUpperCase)
.onClose(() -> System.out.println("zamykanie 3b"))
;
stream3.forEach(System.out::println); stream3.forEach(System.out::println);
stream3.close(); stream3.close();
......
...@@ -43,13 +43,11 @@ public class C02_ZRoznychKlas { ...@@ -43,13 +43,11 @@ public class C02_ZRoznychKlas {
} }
System.out.println(); System.out.println();
Path dir = Paths.get("src"); Path dir = Paths.get("src/main/java");
try { try(Stream<Path> paths = Files.list(dir)) {
Files.list(dir) paths.forEach(f -> System.out.println(f + " " + Files.isRegularFile(f)));
.forEach(f -> System.out.println(f + " " + Files.isRegularFile(f)));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
package gotowe.p40_io; package gotowe.p42_pliki_tekstowe;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
...@@ -9,14 +9,11 @@ public class ZapiszJakisPlik1 { ...@@ -9,14 +9,11 @@ public class ZapiszJakisPlik1 {
System.out.println("Zaczynam"); System.out.println("Zaczynam");
try { try {
PrintWriter out = new PrintWriter("plik1.txt"); PrintWriter out = new PrintWriter("plik1.txt");
out.println("Ala ma kota"); out.println("Ala ma kota");
out.println("Ola ma psa"); out.println("Ola ma psa");
out.append("pies").append(" kot").append(" chomik").println(); out.append("pies").append(" kot").append(" chomik").println();
System.out.println("Gotowe"); System.out.println("Gotowe");
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
package gotowe.p40_io; package gotowe.p42_pliki_tekstowe;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
......
package gotowe.p40_io; package gotowe.p42_pliki_tekstowe;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
......
package gotowe.p40_io; package gotowe.p42_pliki_tekstowe;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
......
package gotowe.p40_io; package gotowe.p42_pliki_tekstowe;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
...@@ -18,7 +18,6 @@ public class ZapiszJakisPlik5 { ...@@ -18,7 +18,6 @@ public class ZapiszJakisPlik5 {
out.append("pies").append(" kot").append(" chomik").println(); out.append("pies").append(" kot").append(" chomik").println();
System.out.println("Gotowe"); System.out.println("Gotowe");
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
package gotowe.p40_io; package gotowe.p42_pliki_tekstowe;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
public class ZapiszJakisPlik1a { public class ZapiszLiczby1 {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Zaczynam"); System.out.println("Zaczynam");
try { try {
PrintWriter out = new PrintWriter("plik1a.txt"); PrintWriter out = new PrintWriter("liczby1.txt");
for(int i = 1; i <= 10_000; i++) {
for (int i = 0; i < 10_000; i++) {
out.println(i); out.println(i);
} }
// nie ma close
System.out.println("Gotowe");
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("Gotowe");
} }
} }
package gotowe.p42_pliki_tekstowe;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class ZapiszLiczby2 {
public static void main(String[] args) {
try {
PrintWriter out = new PrintWriter("liczby2.txt");
for(int i = 1; i <= 9900; i++) {
out.println(i);
if(i % 1000 == 0) {
out.flush(); // wyślij do pliku to, co jest zebrane w buforze
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println("Gotowe");
}
}
package gotowe.p42_pliki_tekstowe;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class ZapiszLiczby3 {
public static void main(String[] args) {
try {
PrintWriter out = new PrintWriter("liczby3.txt");
for(int i = 1; i <= 10_000; i++) {
out.println(i);
}
out.close();
// gdy wykonujemy close(), to nie trzeba robić flush()
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println("Gotowe");
}
}
package gotowe.p42_pliki_tekstowe;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class ZapiszLiczby4 {
// Otwierając plik można ustawić autoFlush=true
// Wszystkie dane będą zapisywane w pliku od razu (nawet gdy nie zrobimy close())
// Ale to zmniejsza wydajność
// Zamykanie zasobów i tak jest zalecane
// TO NIE JEST PRZYKŁAD DO NALADOWANIA
public static void main(String[] args) {
try {
PrintWriter out = new PrintWriter(new FileWriter("liczby4.txt"), true);
for(int i = 1; i <= 10_000; i++) {
out.println(i);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Gotowe");
}
}
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