formfilefield.java
来自「MyUploader 是一款使用 http 协议(RFC 1867)用于上传文件」· Java 代码 · 共 129 行
JAVA
129 行
/*
* Copyright 2006-2007 JavaAtWork All rights reserved.
* Use is subject to license terms.
*/
package javaatwork.myuploader.domain;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* Class that represents a form file field of an HTML form.
*
* @author Johannes Postma - JavaAtWork - http://www.javaatwork.com
*/
public class FormFileField {
private String name = null;
private File file = null;
private String contentType = null;
private String uploadDirectory = null;
/**
* Creates a new FormFileField.
*
* @param name The name of the file field.
* @param file The selected file of the field.
* @param uploadDirectory The upload directory on the server.
* @param contentType The content type of the file.
*/
public FormFileField(String name, File file, String uploadDirectory, String contentType) {
this.name = name;
this.file = file;
this.uploadDirectory = uploadDirectory;
this.contentType = contentType;
}
/**
* Returns the file of the field.
*
* @return The file of the field.
*/
public File getFile() {
return file;
}
/**
* Returns the name of the field.
*
* @return The name of the field.
*/
public String getName() {
return name;
}
/**
* Sets the file of the field.
*
* @param file The file of the field.
*/
public void setFile(File file) {
this.file = file;
}
/**
* Sets the name of the field.
*
* @param name The name of the field.
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the content-type.
*
* @return The content-type.
*/
public String getContentType() {
return contentType;
}
/**
* Set the content-type.
*
* @param contentType The content-type.
*/
public void setContentType(String contentType) {
this.contentType = contentType;
}
/**
* Returns the upload directory.
*
* @return The upload directory.
*/
public String getUploadDirectory() {
return uploadDirectory;
}
/**
* Returns the upload name. The upload name is the
* name of the folder + the file to be uploaded.
* e.g. images/pic001.jpg.
*
* @return The upload name.
*/
public String getUploadName() {
return uploadDirectory + file.getName();
}
/**
* Returns the url encoded upload name. The encoding is based
* on UTF-8.
*
* @return The encoded upload name.
*/
public String getURLEncodedUploadName() {
try {
return URLEncoder.encode(uploadDirectory + file.getName(), "UTF-8");
} catch (UnsupportedEncodingException e) {
return URLEncoder.encode(uploadDirectory + file.getName());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?