strtus上传

private static final int BUFFER_SIZE = 16 * 1024;
    /** 上传的文件*/
    private File loadFile;
    /** 上传的文件类型*/
    private String contentType;
   
    private String imageFileName;
   
    private String caption;
    /**上传文件存放地址*/
    private final String UPLOADPATH = "D:/myfile";
   
/** 上传的文件名*/
private String fileName;
 
    public String execute() throws Exception
{

    imageFileName = fileName;
    /** 文件保存路径*/
File dir = new File(UPLOADPATH);
String newPath = UPLOADPATH +File.separator + imageFileName;
File imageFile = new File(newPath);
if (!dir.exists())
{
dir.mkdirs();
}
copy(loadFile, imageFile);
return SUCCESS;
}

    /** 上传文件方法*/
    private static void copy(File src, File dst)
{
try
{
InputStream in = null;
OutputStream out = null;
try
{
in = new BufferedInputStream(new FileInputStream(src),BUFFER_SIZE);
out = new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
while (in.read(buffer) > 0)
{
out.write(buffer);
}
}
finally
{
if (null != in)
{
in.close();
}
if (null != out)
{
out.close();
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
   
public void addFieldError(String fieldName, String errorMessage)
{
String s = errorMessage;
String f = fieldName;
System.out.println(s);
System.out.println(f);

}

public void setLoadFileContentType(String contentType)
{
this.contentType = contentType;

}

public void setLoadFileFileName(String fileName)
{
this.fileName = fileName;
}

/**
* @return 返回 loadFile
*/
public File getLoadFile()
{
return loadFile;
}

/**
* @param 对loadFile进行赋值
*/
public void setLoadFile(File loadFile)
{
this.loadFile = loadFile;
}

/**
* @return 返回 contentType
*/
public String getContentType()
{
return contentType;
}

/**
* @param 对contentType进行赋值
*/
public void setContentType(String contentType)
{
this.contentType = contentType;
}

/**
* @return 返回 imageFileName
*/
public String getImageFileName()
{
return imageFileName;
}

/**
* @param 对imageFileName进行赋值
*/
public void setImageFileName(String imageFileName)
{
this.imageFileName = imageFileName;
}

/**
* @return 返回 caption
*/
public String getCaption()
{
return caption;
}

/**
* @param 对caption进行赋值
*/
public void setCaption(String caption)
{
this.caption = caption;
}

/**
* @return 返回 fileName
*/
public String getFileName()
{
return fileName;
}

/**
* @param 对fileName进行赋值
*/
public void setFileName(String fileName)
{
this.fileName = fileName;
}

你可能感兴趣的:(F#)