JAVA packs the generated XML and attachments into a. tb file

Source: Internet
Author: User
/**
* Package generated XML and attachments into. TB files
* zipfilestorepath= "D:\\testzip\\test.zip"
* needtozipfilepath= "D:\\testzip\\test"
*
*/
public string Zipallfiletotb (string Zipfilestorepath,
String Needtozipfilepath) {
Bufferedoutputstream BOS = NULL;
try {
BOS = new Bufferedoutputstream (New FileOutputStream (
Zipfilestorepath));
catch (FileNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Zipoutputstream out = new Zipoutputstream (BOS);
F:/yx is a directory with some files and directories below
File F = new file (Needtozipfilepath);
try {
Put (F, Out, "");
Out.close ();
catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return "ZIPALLFILETOTB";
}


public void put (File F, zipoutputstream out, String dir) throws IOException {
int BUFFER = 2048;
if (F.isdirectory ()) {
file[] files = f.listfiles ();
dir = dir + (dir.length () = 0? "": "/") + F.getname ();
for (File file:files) {
Put (file, out, dir);
}
} else {
byte[] data = new Byte[buffer];
FileInputStream fi = new FileInputStream (f);
Bufferedinputstream origin = new Bufferedinputstream (FI, BUFFER);
dir = dir.length () = = 0? "": Dir + "/" + f.getname ();
ZipEntry entry = new ZipEntry (dir);
Out.putnextentry (entry);
int count;
while (count = origin.read (data, 0, BUFFER)!=-1) {
Out.write (data, 0, count);
}
Origin.close ();
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.