⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.java

📁 又一个课程设计 简易 JSP 论坛 功能较简单的那种, 界面上模仿了 Discuz JSP 本来就学的不行, 只是尽量实现了 MVC
💻 JAVA
字号:
package cn.ialvin.web.upload;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class File {
	private byte[] data = null;
	File(byte[] data) {
		this.data = data;
	}
	public byte[] getData() { return this.data; }
	
	private String content_type = "*/*";
	private String typeMIME = "*";
	private String subTypeMIME = "*";
	private final static Pattern p = Pattern.compile("^([^\\/]+)\\/([^\\/]+)$");
	public String getTypeMIME() { return this.typeMIME; }
	public String getSubTypeMIME() { return this.subTypeMIME; }
	void setContentType(String type) {
		if (type == null) return;
		Matcher m = p.matcher(type);
		if (m.find()) {
			this.content_type = type;
			this.typeMIME = m.group(1);
			this.subTypeMIME = m.group(2);
		}
	}
	public String getContentType() { return this.content_type; }

	private String contentDisposition = "form-data";
	void setContentDisposition(String dis) {
		if (dis != null) this.contentDisposition = dis;
	}
	public String getContentDisposition() { return this.contentDisposition; }

	private String f_name = "";
	void setFormName(String n) { if (n != null) this.f_name = n; }
	public String getFormName() { return this.f_name; }

	private String name = "";
	public String getName() { return this.name; }

	private String path = "";
	public String getPath() { return this.path; }

	private String ext = "";
	public String getExt() { return this.ext; }

	private String pn = "";
	void setPathName(String pn) {
		if (pn == null) return;
		this.pn = pn;
		String s = pn.replace('/', '\\');
		int pos = s.lastIndexOf('\\');
		if (pos >= 0) {
			this.name = s.substring(pos + 1);
			this.path = s.substring(0, pos + 1);
		} else {
			this.name = s;
		}
		pos = this.name.lastIndexOf('.');
		if (pos >= 0) {
			this.ext = this.name.substring(pos+1);
		}
	}
	public String getPathName() { return this.pn; }

	public static void main(String[] a) {
		System.out.println("abc".substring("abc".lastIndexOf('c')+1));
	}
	
	public int size() { return this.data.length; }
	public boolean saveAs(java.io.File file, boolean overwrite) {
		if (file == null) return false;
		if (file.isDirectory()) file = new java.io.File(file, this.name);
		FileOutputStream o = null;
		try {
			o = new FileOutputStream(file);
			o.write(this.data);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return false;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		} finally {
			try { if (o != null) o.close(); } catch (IOException e) {}
		}
		return true;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -