檔案的拷貝拷貝:以程式作為中轉,把輸入流和輸出流合二為一
* 工具類:1.封裝操作和釋放資源步驟,簡化**
檔案和資料夾都可以拷貝/*
檔案的拷貝
1.檔案到程式
2.程式到檔案
*/public static void filecopy(string srcpath,string detapath)
os.flush();
} catch (filenotfoundexception e) catch (ioexception e) finally
} catch (ioexception e)
try
} catch (ioexception e)
}}
工具類:jdk1.7對資源釋放做了處理:try...with...resource:(因為我的是1.8的,沒做測試)public static void dircopy(file file, file tofile)
//遍歷資料夾
for (file f : file.listfiles())
} else
try
} catch (filenotfoundexception e) catch (ioexception e) finally
} catch (ioexception e)
try
} catch (ioexception e) }}
}
自己封裝:先對釋放資源步驟進行封裝public static void filecopytopack1(inputstream is ,outputstream os)
// os.flush();
// } catch (filenotfoundexception e) catch (ioexception e)
// }
釋放資源步驟再簡化public static void close(inputstream is ,outputstream os)
} catch (ioexception e)
try
} catch (ioexception e)
}
/*
釋放資源再簡化,引數是可變引數,類似於陣列,可以乙個也可以多個,增加了靈活性。
因為inputstream和outputstream都實現於closeable介面
*/public static void close(closeable... ios)
} catch (ioexception e)
}}
inputstream和outputstream都實現於closeable介面
封裝操作步驟和釋放步驟public abstract class inputstream implements closeable
public abstract class outputstream implements closeable, flushable
呼叫://封裝操作和釋放步驟,只要傳入輸入輸出流就行了。
public static void filecopytopack(inputstream is ,outputstream os)
os.flush();
} catch (filenotfoundexception e) catch (ioexception e) finally
}
//檔案到檔案
try catch (ioexception e)
//檔案到位元組陣列
byte datas =null;
try catch (ioexception e)
//位元組陣列到檔案
try catch (ioexception e)
PHP封裝成類(檔案上傳)
uploadfile.class.php created by phpstorm.user huang date 2017 7 19 time 23 20 header content type text html charset utf 8 new new upload class upload ...
音效工具類的封裝
與單例類的比較 類方法的特點 import inte ce sppsoundplaymanager nsobject param name 聲音檔名 帶字尾 param alert 是否振動 void playsoundwithname nsstring name alert bool alert ...
spUtil工具類的封裝
工具類的作用是為了讓我們更方便的使用,一次封裝,多次使用,也是乙個合格的工程師必備的 技術,下面就是sp存值和取值的工具類封裝public class sputil else if value instanceof boolean else if value instanceof float els...