background preloader

Data Merge

Facebook Twitter

Java - Merging two images. How to write to file in Java – FileOutputStream. In Java, FileOutputStream is a bytes stream class that’s used to handle raw binary data. To write the data to file, you have to convert the data into bytes and save it to file. See below full example. How do I join multiple files into one (I/O and Streams forum at JavaRanch) How to merge two input streams in java. Today I got a requirement to read two property files using streams and then iterate through whole content of two files to identify the duplicate keys.

So I have written code using FileInputStream and then BufferedReader to read the content line by line. But so far I read only one file. Still one more file need to be read to get the content. So I was wondering are there any streams available in java.io which actually takes multiple FileInputStreams or files and gives an input stream after merging which I can pass it to BufferedReader......!!!!!! Then I have come across SequenceInputStream which just serves the same. Here SequenceInputStream takes FileInputStreams like FileInputStream fis1 = new FileInputStream("com/naresh/message/CustomApplicationResources.properties");FileInputStream fis2 = new FileInputStream("com/naresh/message/ApplicationResources.properties"); new SequenceInputStream(fis1, fis2); and this is an instance of InputStream as SequenceInputStream extends InputStream.

Thanks :) SequenceInputStream. 如果您使用SequenceInputStream就不用這麼麻煩,SequenceInputStream可以看作是數個 InputStream物件的組合,當一個InputStream物件的內容讀取完畢後,它就會取出下一個InputStream物件,直到所有的 InputStream物件都讀取完畢為止。 Package onlyfun.caterpillar; import java.util.*; import java.io.*; // 分割檔案 public static void seperate(String filename, int size) throws IOException { FileInputStream fileInputStream = new FileInputStream(new File(filename)); BufferedInputStream bufInputStream = new BufferedInputStream(fileInputStream); byte[] data = new byte[1]; int count = 0; // 從原檔案大小及指定分割的大小 // 決定要分割為幾個檔案 if(fileInputStream.available() % size == 0) count = fileInputStream.available() / size; else count = fileInputStream.available() / size + 1; // 開始進行分割 for(int i = 0; i < count; i++) { int num = 0; // 分割的檔案加上底線與編號 File file = new File(filename + "_" + (i + 1)); BufferedOutputStream bufOutputStream = new BufferedOutputStream( new FileOutputStream(file)); while(bufInputStream.read(data) !

If(num < size) { bufOutputStream.flush(); bufOutputStream.close(); } } How to merge multiple images into one image - Java ImageIO | kalani's Tech blog. My previous post shows how to split an image into chunks. Now let's see how to merge multiple images into one image. Say we need to concatenate following four image chunks. I got these chunks by splitting the image in the right hand side, using the image splitter.

Following code shows how to concatenate the image chunks above into one image.