---
title: "为什么我上传后的文件无法从服务器删除？"
author: "yourgame"
date: "2009-02-08T23:20:11Z"
tags: ["C", "C#", "C++"]
categories: ["非技术"]
slug: "untitled"
draft: false
lastmod: "2009-02-08T23:20:57Z"
id: 325342
url: "https://yourgame.iteye.com/blog/325342"
---

```java
new ZipOutputStream(new FileOutputStream("c:/abc.txt"));
```

在操作文件或者流的时候最好不要这么写，因为这么写你无法在finally里面将流最终关闭，所以当您要删除文件的时候就会有IOException,最终导致文件无法删除！

```java

public String compressionFiles() {
        ZipOutputStream zosm = null;
		FileOutputStream fosm = null;
		try {
			fosm = new FileOutputStream("c:/abc.txt");
			zosm = new ZipOutputStream(fosm);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (zosm != null) {
				zosm.close();
			}
			if (fosm != null) {
				fosm.close();
			}
		}
}

```

这样分开出来写，就可以保证所有的流最后都可以在finally中被正确关闭。