src/util/UploadUtil.java

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package util;

import org.apache.struts.upload.FormFile;


import java.io.*;

public class UploadUtil {
	private FormFile formFile = null;

	// �ļ���׺��
	private String fileExt = "";

	// ���
	private String fileName = "";

	// �ļ���С
	private int fileSize = 0;

	private String fileContentType = "";

	/**
	 * 调用方法:<br>
	 * UploadUtil upload = new UploadUtil(<FormFile>picture);<br>
	 * upload.saveFile(<String>strAbsPath + picture);<br>
	 * 防止重名
	 * Explorer.renameTo(strAbsPath + picture, newPath);<br>
	 * @param file
	 */
	public UploadUtil(FormFile file) {

		this.formFile = file;

		fileName = formFile.getFileName().trim();
		fileSize = formFile.getFileSize();
		fileContentType = formFile.getContentType();

		if (null != fileName) {
			int temp = fileName.lastIndexOf(".");
			if (-1 != temp) {
				fileExt = fileName.substring(temp + 1);
			}
		}
	}
	
	public UploadUtil() {

	}

	public void saveFile(String filePath) {

		try {
			Explorer.existsAndCreateParent(filePath);
			// retrieve the file data
			InputStream stream = formFile.getInputStream();
			// write the file to the file specified
			OutputStream bos = new FileOutputStream(filePath);
			int bytesRead = 0;
			byte[] buffer = new byte[8192];
			while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
后面还有 129 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。