延迟删除临时文件

下载文件完毕后删除临时文件:
public InputStream getInputStream() {
		InputStream is = null;
		
		try {
			is = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		Thread t = new Thread(new Runnable() {

			public void run() {
				try {
					// 线程睡30秒
					Thread.sleep(30000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				// 删除临时文件
			
				file.delete();
			}
		});
		t.start();
		return is;
	}

你可能感兴趣的:(java,thread)