मैंने स्मृति में कई बुफर्ड इमेज उत्पन्न किए हैं और मैं इसे ईमेल संलग्नक के रूप में भेजने से पहले उन्हें एक ज़िप फ़ाइल में संपीड़ित करना चाहता हूं। डिस्क से फ़ाइलों को पढ़ने के बिना मैं फ़ाइलों को ज़िप में कैसे सहेज सकता हूं।जावा के साथ डिस्क पर सहेजे बिना मैं ज़िप फ़ाइल कैसे उत्पन्न कर सकता हूं?
क्या कोई तरीका है कि मैं एक temp फ़ाइल बनाये बिना उन फ़ाइलों को संपीड़ित कर सकता हूं?
डिस्क पर लेखन हजारों फाइलों के निर्माण के कारण समय लेने वाला है।
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cccprog;
import java.awt.Component;
import java.awt.Panel;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
/**
*
* @author Z
*/
public class N {
public static void main(String[] args) throws Exception {
for (int i = 0; i < 10; i++) {
JFrame jf = new JFrame();
Panel a = new Panel();
JRadioButton birdButton = new JRadioButton();
birdButton.setSize(100, 100);
birdButton.setSelected(true);
jf.add(birdButton);
getSaveSnapShot(birdButton, i + ".bmp");
}
}
public static BufferedImage getScreenShot(Component component) {
BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
// paints into image's Graphics
component.paint(image.getGraphics());
return image;
}
public static void getSaveSnapShot(Component component, String fileName) throws Exception {
BufferedImage img = getScreenShot(component);
// BufferedImage img = new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_BYTE_BINARY);
// write the captured image as a bmp
ImageIO.write(img, "bmp", new File(fileName));
}
}
java.utli.zip पर देखें। –
बस मेरी जिज्ञासा के लिए, आप एक temp फ़ाइल बनाने से बचना क्यों चाहते हैं? –
यह संबंधित लगता है http://stackoverflow.com/questions/7108035/how-to-flush-the-zipoutputstream-periodically-in-java – Ted