- java的iterator.remove()注意
iterator.remove()
前不能改變原list的size()
.
- java使用BufferedReader中文輸出亂碼
java
//需要指定charset
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GB2312"));
- 使用FileChannel提高複製文件效率
/**
* 複製文件
* @param src 源文件
* @param dest 目的文件
* @throws IOException
*/
public static void copyFile(File src, File dest) throws IOException {
if (!src.exists()) {
throw new FileNotFoundException("source file not found.");
}
dest.getParentFile().mkdirs();
FileInputStream inStream = null;
FileOutputStream outStream = null;
FileChannel in = null;
FileChannel out = null;
try {
inStream = new FileInputStream(src);
outStream = new FileOutputStream(dest);
in = inStream.getChannel();
out = outStream.getChannel();
in.transferTo(0, in.size(), out);
} catch (IOException e) {
throw e;
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
if (inStream != null) {
inStream.close();
}
if (outStream != null) {
outStream.close();
}
}
}