/**
* 根据路径和样式获取文件大小的字符串
*
* @param fileName
* 根据文件路径
* @param size
* 文件大小样式(KB或MB或GB)
* @return
*/
public static String size(String fileName, String size) {
return size(newFile(fileName), size);
}
private InputStream is;
private OutputStream os;
private FileUtil() {
}
private void setInputStreamAndOutputStream(InputStream is, OutputStream os) {
this.is = is;
this.os = os;
}
private void copyThread(File f1, File f2, boolean append) {
try {
is = new FileInputStream(f1);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
os = new FileOutputStream(f2, append);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public void run() {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(is);
bos = new BufferedOutputStream(os);
byte[] barr = new byte[1024];
int len = 0;
while ((len = bis.read(barr)) != -1) {
bos.write(barr, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bis != null)
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
if (bos != null)
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
组合并且封装了File的一些方法,文件路径就是File对象。
上边都是字符流,至于线程开启字符流的的运算,加油,你可以的。