释放资源之IO工具类

public class IOUtils {
	
	private static final String TAG = "IOUtils";
	
	public static void closeSilently(Closeable c) {
		if (c == null)
			return;
		try {
			c.close();
		} catch (Throwable t) {
			Log.w(TAG, "fail to close", t);
		}
	}

	public static void closeSilently(ParcelFileDescriptor c) {
		if (c == null)
			return;
		try {
			c.close();
		} catch (Throwable t) {
			Log.w(TAG, "fail to close", t);
		}
	}
	
	public static void closeSilently(Cursor cursor) {
    try {
    	if (cursor != null) cursor.close();
     } catch (Throwable t) {
    	 Log.w(TAG, "fail to close", t);
     }
	 }
}

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