package up.down.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.nio.Buffer;
import java.util.Date;
import org.apache.axis.message.InputStreamBody;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.ProgressListener;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts.upload.DiskFile;
public class Test {
public static void main(String[] args) {
File file = new File("./build/期 日 未 収 入 金 内 訳 帳.xml");
File writefile = new File("./build/writefile.txt");
String upload="F:/期 日 未 収 入 金 内 訳 帳.xml.bak";
if(file.exists()){
System.out.println("--->文件存在");
try {
readfile(file); //读取
writfile(writefile,readfile(file)); //创建文件写入
//uploadfile(upload); //上传文件
} catch (Exception e) {
e.printStackTrace();
}
}else{
System.out.println("-->文件不存在exists");
}
}
//读取文件
public static StringBuffer readfile(File file) throws IOException{
System.out.println("读取开始时间:"+new Date());
BufferedReader br = new BufferedReader(new FileReader(file));
System.out.println("文件大小:"+file.length()/1000+"KB");
StringBuffer line = new StringBuffer();
String str = null;
while((str=br.readLine())!=null){
line.append(str);
line.append("\n");
}
System.out.println("--->"+line);
System.out.println("读取结束时间="+new Date());
br.close();
return line;
}
//写入文件将读取的文件内容保存在制定的工程目录下
public static void writfile(File file,StringBuffer sb) throws Exception{
FileWriter fw = new FileWriter(file);
fw.getEncoding().getBytes("utf-8");
fw.write(sb.toString());
System.out.println("------->写入成功!");
System.out.println("写入了一个大小为"+file.length()/1000+"KB的文件");
fw.close();
}