123
This commit is contained in:
parent
96d7d672e8
commit
f91fd7f2bb
|
@ -40,7 +40,7 @@ public class BuchstabenAnagramme {
|
||||||
if (word.indexOf(letter) > 0 && foundWords.indexOf(w) < 0 && w.length() <= wordChars.length
|
if (word.indexOf(letter) > 0 && foundWords.indexOf(w) < 0 && w.length() <= wordChars.length
|
||||||
&& notTooManyLetters(w.toCharArray(), wordChars) && sameLetters(w.toCharArray(), wordChars)) {
|
&& notTooManyLetters(w.toCharArray(), wordChars) && sameLetters(w.toCharArray(), wordChars)) {
|
||||||
foundWords.add(w);
|
foundWords.add(w);
|
||||||
System.out.println(foundWords.get(foundWords.size() - 1));
|
System.out.print("[" + foundWords.get(foundWords.size() - 1) + "]");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
58
Udemy-Java-Kurs-Streams/src/MehrereTexteEinlesen.java
Normal file
58
Udemy-Java-Kurs-Streams/src/MehrereTexteEinlesen.java
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.SequenceInputStream;
|
||||||
|
|
||||||
|
public class MehrereTexteEinlesen {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
|
|
||||||
|
File file1 = new File("C:\\Users\\Spike\\Desktop\\text1.txt");
|
||||||
|
File file2 = new File("C:\\Users\\Spike\\Desktop\\text2.txt");
|
||||||
|
|
||||||
|
// Einlesen in bytes
|
||||||
|
InputStream iStream1 = null;
|
||||||
|
InputStream iStream2 = null;
|
||||||
|
|
||||||
|
SequenceInputStream sInputStream = null;
|
||||||
|
|
||||||
|
OutputStream fOutputStream = new FileOutputStream("C:\\Users\\Spike\\Desktop\\text3.txt");
|
||||||
|
|
||||||
|
int i;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// gehe zu file 1 \ 2 und lese per byte ein
|
||||||
|
iStream1 = new FileInputStream(file1);
|
||||||
|
iStream2 = new FileInputStream(file2);
|
||||||
|
|
||||||
|
// Gleichzeitig einlesen
|
||||||
|
sInputStream = new SequenceInputStream(iStream1, iStream2);
|
||||||
|
|
||||||
|
// Während eingelesen wird, werden bytes in in gespeichert und in buchstaben umgewandelt
|
||||||
|
|
||||||
|
while((i = sInputStream.read()) != -1){
|
||||||
|
c = (char) i;
|
||||||
|
System.out.print(c);
|
||||||
|
// Schreibt in die datei
|
||||||
|
fOutputStream.write(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
|
iStream1.close();
|
||||||
|
iStream2.close();
|
||||||
|
sInputStream.close();
|
||||||
|
fOutputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
package de.downloadmanager;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
//Implementiert Runable interface um ein Thread zu starten
|
||||||
|
public class DownloadManager implements Runnable {
|
||||||
|
|
||||||
|
private String link; // Downloadlink
|
||||||
|
private File outputFile;// Ort wo File gespeichert wird
|
||||||
|
|
||||||
|
private String fileSeperator = System.getProperty("file.seperator"); // Fileseperator erkennt das system
|
||||||
|
private String downloadFolderPath = "C:\\Users\\Spike\\Desktop\\Testdownloads";
|
||||||
|
|
||||||
|
//fileSeperator + "Users" + fileSeperator + "Spike" + fileSeperator + "Desktop" + fileSeperator + "TestDownloads";
|
||||||
|
|
||||||
|
|
||||||
|
private File defaultDownloadFolder = new File(downloadFolderPath);//Standard Ordner setzen
|
||||||
|
|
||||||
|
public DownloadManager(String link) {
|
||||||
|
this.link = link;
|
||||||
|
|
||||||
|
|
||||||
|
// Prüft ob Ordner vorhanden wenn nicht wird er erstellt
|
||||||
|
|
||||||
|
if(! defaultDownloadFolder.exists()) {
|
||||||
|
defaultDownloadFolder.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
URL url = new URL(link);
|
||||||
|
//Casten, damit die Url in hConnection gespeichert wird
|
||||||
|
HttpURLConnection hConnection = (HttpURLConnection)url.openConnection();
|
||||||
|
|
||||||
|
// Inputstream -> Bytes
|
||||||
|
|
||||||
|
BufferedInputStream bInputstream = new BufferedInputStream(hConnection.getInputStream());
|
||||||
|
|
||||||
|
// Datei schreiben / erstellen
|
||||||
|
|
||||||
|
outputFile = new File(defaultDownloadFolder, "datei.mp3");
|
||||||
|
OutputStream outputStream = new FileOutputStream(outputFile);
|
||||||
|
BufferedOutputStream bOutputStream = new BufferedOutputStream(outputStream, 1024); // 1024 Wie groß der Puffer sein soll
|
||||||
|
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
|
int downloaded = 0;
|
||||||
|
int readByte = 0;
|
||||||
|
|
||||||
|
while((readByte = bInputstream.read(buffer, 0, 1024)) >= 0) {
|
||||||
|
bOutputStream.write(buffer, 0,readByte);
|
||||||
|
downloaded += readByte;
|
||||||
|
|
||||||
|
System.out.println("Bereits " + downloaded + " Bytes " + " geladen");
|
||||||
|
}
|
||||||
|
bOutputStream.close();
|
||||||
|
bInputstream.close();
|
||||||
|
System.out.println("Download erfolgreich!");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
15
Udemy-Java-Kurs-Streams/src/de/downloadmanager/Main.java
Normal file
15
Udemy-Java-Kurs-Streams/src/de/downloadmanager/Main.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package de.downloadmanager;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
// DownloadManager dManager = new DownloadManager("Test");
|
||||||
|
|
||||||
|
String downloadLink = "https://audiobible.com/templates/__custom/images/audio/kjv-scourby-genesis-1.mp3";
|
||||||
|
|
||||||
|
new Thread(new DownloadManager(downloadLink)).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user