======================文件上传====================
=======================以下是我的实现==========================
=============================================================
问题:在把文件上传也就是从新写入一个新文件的时候....在读取字节时第一个字节未能读取这是???
private static final int BUFFER_SIZE = 16 * 1024 ;
public boolean upload(File url) {
boolean bo = false;
try {
InputStream in = null;
OutputStream out = null;
try {
String fileName = url.getPath();
// 文件后缀名
String fileType = "."
+ fileName.substring(fileName.lastIndexOf('.') + 1);
String name = "phone" + fileType;
String dir = "C:/uploadclass";
System.out.println("当前要上传的文件路径:" + dir);
File file = new File(dir + File.separator + name);
System.out.println("上传后文件路径:" + file.getCanonicalPath());
in = new BufferedInputStream(new FileInputStream(url),BUFFER_SIZE);
out = new BufferedOutputStream(new FileOutputStream(file),BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
System.out.println("========:" +in.available());
int num=0;
while (-1!=(num=in.read(buffer))) {
out.write(buffer);
}
out.flush();
buffer=null;
} finally {
if (null != in) {
in.close();
}
if (null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return bo;
}
public static void main(String[] args) {
GetDate date = new GetDate();
File file = new File("d://xss.txt");
date.upload(file);
}
=====================上传前的文本内容==========================
13639048253
13639048251
************************上传后的文本内容*****************************
3639048253
13639048251
1不见了???
问题补充:
不是吧?
难道是我的机子问题??
问题补充:
===============115893520 谢谢================
但是有个问题
这个上传后.文件大小为:几百MB,,有时候甚至为几G··
这是为啥?