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/period not survival into gold registered account. xml");
File WriteFile = new File ("./build/writefile.txt");
String upload= "f:/period is not survival into the gold registered account. Xml.bak";
if (file.exists ()) {
SYSTEM.OUT.PRINTLN ("---> Document exists");
try {
ReadFile (file); Read
Writfile (writefile,readfile (file)); Creating file Writes
UploadFile (upload); Uploading files
catch (Exception e) {
E.printstacktrace ();
}
}else{
System.out.println ("--> file does not exist exists");
}
}
Reading files
public static StringBuffer ReadFile (file file) throws ioexception{
System.out.println ("Read start time:" +new Date ());
BufferedReader br = new BufferedReader (new FileReader (file));
SYSTEM.OUT.PRINTLN ("File Size:" +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 ("read end time =" +new Date ());
Br.close ();
return line;
}
Write the file to save the contents of the read file in the engineering directory
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 ("-------> Write succeeded. ");
System.out.println ("Write a file of size" +file.length ()/1000+ "KB");
Fw.close ();
}