- diandidemeng
- 等级:
- 性别:
- 文章: 46
- 积分: 109
- 来自: 深圳
|
java 代码
-
-
-
-
-
-
-
-
- public boolean zip(String inputFileName, String outputFileName){
- boolean bNodFoundFile=true;
- ZipOutputStream out = null;
- try {
- out = new ZipOutputStream(new FileOutputStream(
- outputFileName));
- zip(out, new File(inputFileName), "");
-
- out.close();
- } catch (IOException e) {
- bNodFoundFile=false;
- }finally{
- if(out!=null){
- try {
- out.close();
- out=null;
- } catch (IOException e) {
- }
- }
- }
-
- return bNodFoundFile;
- }
-
- private void zip(ZipOutputStream out, File f, String base){
- FileInputStream in =null;
- try{
- if (f.isDirectory()) {
- File[] fl = f.listFiles();
-
- if (System.getProperty("os.name").startsWith("Windows")) {
- base = base.length() == 0 ? "" : base + "\\";
- out.putNextEntry(new ZipEntry(base));
- } else {
- base = base.length() == 0 ? "" : base + "/";
- out.putNextEntry(new ZipEntry(base));
- }
- int indexSize=fl.length;
- for (int i = 0; i < indexSize; i++) {
- zip(out, fl[i], base + fl[i].getName());
- }
- } else {
- out.putNextEntry(new ZipEntry(base));
- in = new FileInputStream(f);
- int b;
- byte[] buffer = new byte[4096];
- while ((b = in.read(buffer)) != -1) {
- out.write(buffer,0,b);
- }
- }
- }catch(IOException e){
- } finally{
- try {
- if(in!=null){
- in.close();
- in=null;
- }
- } catch (IOException e1) {
- }
- }
- }
-
-
-
-
-
-
- public void deleteFile(final String deleteFilePath){
- File file=new File(deleteFilePath);
- deleteFile(file);
- file.delete();
- }
-
-
-
-
-
- private void deleteFile(File file){
- if(file.isDirectory()){
- File[] fl = file.listFiles();
- int indexSize=fl.length;
- for(int i=0; i<indexSize; i++){
- deleteFile(fl[i]);
- }
-
- file.delete();
- }else{
-
- file.delete();
- }
- }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|