`

上传的控件把它以byte[]的形式保存到本地的硬盘中

阅读更多

(1)页面:

<s:decorate id="coverField" template="../layout/edit.xhtml" >
	<ui:define name="label">Upload Watermark</ui:define>
	<s:fileUpload id="cover" data="#{waterMarkManager.localPath}" onkeypress="return false;"  accept="images/*" contentType="image/*" fileSize="10000000" fileName="#{waterMarkManager.currentFileName}"
		size="23">
	</s:fileUpload>
</s:decorate>

 (2)类中:

private byte[] localPath;

public byte[] getLocalPath() {
	return localPath;
}

public void setLocalPath(byte[] localPath) {
	this.localPath = localPath;
}

 

(3)FTPTools.java类:

public File getFileFromBytes(byte[] b, String outputFile){
		BufferedOutputStream stream = null; 
        File file = null; 
        try{ 
            file = new File(outputFile); 
            FileOutputStream fstream = new FileOutputStream(file); 
            stream = new BufferedOutputStream(fstream); 
            stream.write(b); 
        } catch (Exception e){ 
            e.printStackTrace(); 
        } finally{ 
            if (stream != null){ 
                try{ 
                    stream.close(); 
                } catch (IOException e1){ 
                    e1.printStackTrace(); 
                } 
            } 
        } 
        return file; 

}

 这样上传的文件或者图片就会保存到本地的硬盘中了,就是利用上面那个方法就可以搞定。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics