Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
Das kannst Du realisieren, indem Du nacheinander beide Dateien öffnest, ausliest und zwischenpufferst
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
public class FileCopyExample
{
public static void main(String[] args)throws Exception
{
FileInputStream fis1 = new FileInputStream("C:/test1.txt");
FileInputStream fis2 = new FileInputStream("C:/test2.txt");
FileChannel fic1 = fis1.getChannel();
FileChannel fic2 = fis2.getChannel();
FileOutputStream fos = new FileOutputStream("C:/test3.txt");
FileChannel foc = fos.getChannel();
copy(fic1, foc);
copy(fic2, foc);
fis1.close();
fis2.close();
fos.close();
}
private static void copy(FileChannel in, FileChannel out)throws Exception{
long position = 0;
long transfered;
long remaining = in.size();
while(remaining > 0){
transfered = in.transferTo(position, remaining, out);
position += transfered;
remaining -= transfered;
}
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class FileCopyBufferExample
{
public static void main(String[] args) throws Exception
{
FileInputStream fis1 = new FileInputStream("C:/test1.txt");
FileInputStream fis2 = new FileInputStream("C:/test2.txt");
FileOutputStream fos = new FileOutputStream("C:/test3.txt");
copy(fis1, fos);
copy(fis2, fos);
fis1.close();
fis2.close();
fos.close();
}
private static void copy(InputStream in, OutputStream out) throws Exception
{
int length;
byte[] buffer = new byte[8192];
while ((length = in.read(buffer)) != -1)
{
out.write(buffer, 0, length);
}
}
}
/**
*
*/
package de.tutorials;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* @author Thomas.Darimont
*
*/
public class MergeFileContentExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
File inputFile = new File("c:/file1.txt");
File anotherInputFile = new File("c:/file2.txt");
File outputFile = new File("c:/mega_file.txt");
mergeFilesInto(outputFile, inputFile, anotherInputFile);
}
/**
* @param inputFile
* @param anotherInputFile
* @param outputFile
* @throws IOException
* @throws FileNotFoundException
*/
private static void mergeFilesInto(File outputFile, File... inputFiles)
throws IOException, FileNotFoundException {
PrintWriter printWriter = new PrintWriter(new BufferedWriter(
new FileWriter(outputFile)));
for (File inputFile : inputFiles) {
writeFileContentsTo(inputFile, printWriter);
}
printWriter.close();
}
/**
* @param file
* @param printWriter
* @throws FileNotFoundException
*/
private static void writeFileContentsTo(File file, PrintWriter printWriter)
throws FileNotFoundException {
Scanner inputScanner = new Scanner(file);
while (inputScanner.hasNextLine()) {
printWriter.println(inputScanner.nextLine());
}
inputScanner.close();
}
}
C:\Dokumente und Einstellungen\Thomas.Darimont>type file1.dat file2.dat > mergedfile.dat