package com.blog.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/** 文件的工具类 */
public class IOUtils {
/** 一次性将文件读取到数组中 */
public static byte[] read(String file) throws IOException {
return read(new File(file));
}
public static byte[] read(File file)
throws IOException {
// 按照文件大小 创建返回byte[]数组
byte[] buf = new byte[(int) file.length()];
// 用RAF只读打开文件
RandomAccessFile raf = new RandomAccessFile( file, "r");
// 使用 raf.read(byte[]) 读取全部内容
raf.read(buf);
// 关闭文件
raf.close();
return buf;
}
/** 复制文件, 复制in到out */
public static void cp(String in, String out)
throws IOException {
cp(new File(in), new File(out));
}
public static void cp(File in, File out)
throws IOException {
InputStream fin = new FileInputStream(in);// 可以使用File构造
OutputStream fout = new FileOutputStream(
out);
cp(fin, fout);
fin.close();
fout.close();// 关闭
}
/** 复制文件, 复制in到out, 不关闭流 */
public static void cp(InputStream in,
OutputStream out) throws IOException {
byte[] buf = new byte[1024 * 512];// 512K缓冲
int count;
while ((count = in.read(buf)) != -1) {// 读取到buf
// System.out.println(count);//
out.write(buf, 0, count); // 写入到输出流
}
out.flush(); // 刷出缓冲到目标流
}
/** 不开缓冲 */
public static void cp2(InputStream in,
OutputStream out) throws IOException {
int b;
while ((b = in.read()) != -1) { // 读取一个byte
out.write(b); // 写入到输出流
}
out.flush(); // 刷出缓冲到目标流
}
public static byte[] read(InputStream in)
throws IOException {
byte[] buf = new byte[in.available()];
in.read(buf);
in.close();
return buf;
}
public static String toHexString(byte[] ary) {
if (ary == null || ary.length == 0)
return "";
StringBuilder buf = new StringBuilder();
if ((ary[0] & 0xff) <= 0xf) {
buf.append("0");
}
buf.append(Integer
.toHexString(ary[0] & 0xff));
for (int i = 1; i < ary.length; i++) {
buf.append(",");
if ((ary[i] & 0xff) <= 0xf) {
buf.append("0");
}
buf.append(Integer
.toHexString(ary[i] & 0xff));
}
return buf.toString();
}
public static String readHexString(
String filename) throws IOException {
return toHexString(read(filename));
}
/**
* 将文件切分为 指定大小的系列文件 如: IOUtiles.split("test.zip", 1024) 将文件 test.zip 切分为
* 1024K(1M) 大小的 系列文件 : test.zip.0, test.zip.1,...
*
* @param filename
* 源文件名
* @param size
* 文件大小, 以k为单位
*/
public static void split(String file,
int size) throws IOException {
if (size <= 0) {
throw new IllegalArgumentException(
"搞啥呀!");
}
int idx = 0;// 文件的序号
InputStream in = new BufferedInputStream(
new FileInputStream(file));
OutputStream out = new BufferedOutputStream(
new FileOutputStream(file + "."
+ idx++));
int b;
int count = 0;
while ((b = in.read()) != -1) {
out.write(b);
count++;
if (count % (size * 1024) == 0) {
out.close();
out = new BufferedOutputStream(
new FileOutputStream(file + "."
+ idx++));
}
}
in.close();
out.close();
}
/**
* 连接上面方法的系列文件为一个文件 如: IOUtiles.join("test.zip.0"); 在硬盘上生成一个没有序号的文件: test.zip
*
* @param basename
* 第一个文件, 如test.zip.0
*/
public static void join(String file)
throws IOException {
String filename = file.substring(0, file
.lastIndexOf("."));
String num = file.substring(file
.lastIndexOf(".") + 1);
int idx = Integer.parseInt(num);
OutputStream out = new FileOutputStream(
filename);
File f = new File(filename + "." + idx++);
while (f.exists()) {
InputStream in = new FileInputStream(f);
cp(in, out);
in.close();
f = new File(filename + "." + idx++);
}
out.close();
}
/**
* 将对象序列化到数组中 可以使用变长数组实现, 或者ByteArrayOutputStream实现
*
* @param obj
* 一个实现序列化接口的对象
* @return 数组对象
* @throws IOException
*/
public static byte[] serialize(
Serializable obj) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(
os);
out.writeObject(obj);// 对象序列化, foo
out.close();
byte[] ary = os.toByteArray();
return ary;
}
/**
* 反序列化byte数组 到对象
*
* @param ary
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
public static Object unserialize(byte[] data)
throws IOException,
ClassNotFoundException {
ObjectInputStream in = new ObjectInputStream(
new ByteArrayInputStream(data));
Object o = in.readObject();// 反序列化
in.close();
return o;
}
/**
* 获取目录的全部文件
*
* @param dir
* @return
*/
public static List<File> listFile(File dir) {
File[] files = dir
.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isFile();
}
});
return new ArrayList<File>(Arrays
.asList(files));
}
/**
* 获取目录的全部文件, 指定扩展名的文件
*
* @param dir
* @return
*/
public static List<File> listFile(File dir,
final String ext) {
File[] files = dir
.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isFile()
&& pathname.getName()
.endsWith(ext);
}
});
return new ArrayList<File>(Arrays
.asList(files));
}
/**
* 递归获取目录的全部文件
*
* @param dir
* @return
*/
public static List<File> listAll(File dir) {
List<File> all = listFile(dir);
File[] subs = dir
.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
for (File sub : subs) {
all.addAll(listAll(sub));
}
return all;
}
/**
* 递归获取目录的全部文件, 指定扩展名的文件
*
* @param dir
* @return
*/
public static List<File> listAll(File dir,
String ext) {
List<File> all = listFile(dir, ext);
File[] subs = dir
.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
for (File sub : subs) {
all.addAll(listAll(sub, ext));
}
return all;
}
public static String readLine(InputStream in)
throws IOExc
没有合适的资源?快使用搜索试试~ 我知道了~
javaweb+SSH2个人博客系统MVC
共665个文件
js:215个
png:71个
jpg:71个
1星 需积分: 9 23 下载量 179 浏览量
2018-05-17
09:44:54
上传
评论 1
收藏 21.16MB RAR 举报
温馨提示
该系统采用三大框架编写,MVC设计模式,c3p0数据连接池,ckediter富文本编辑器,拦截器 jquery实现的炫酷相册。。。 前台地址:http://localhost:8080/blog/index/index 后台地址:http://localhost:8080/blog/manage/login 后台账号:admin 密码:123456 访问http://localhost:8080/blog 可直接跳转到前台 首页、关于我、慢生活、我的相册、留言板 首页 这是高大上的相册 后台功能: 可以在后台管理博客内容 文章的增、删、改 相册的管理(新建相册,删除相册) 相册相片管理功能 留言板管理
资源推荐
资源详情
资源评论
收起资源包目录
javaweb+SSH2个人博客系统MVC (665个子文件)
IOUtils.class 8KB
ArticleServiceImpl.class 5KB
CritiqueServiceImpl.class 4KB
ArticleShowAction.class 4KB
CritiqueShowAction.class 3KB
Article.class 3KB
ArticleServiceImplTest.class 3KB
ImageUtil.class 3KB
PhotoServiceImplTest.class 3KB
ImageUpload.class 3KB
Photo.class 3KB
LoginAction.class 3KB
PhotoServiceImpl.class 2KB
MessageShowAction.class 2KB
ManagerServiceImpl.class 2KB
Album.class 2KB
CritiqueServiceImplTest.class 2KB
Critique.class 2KB
ArticleDetailAction.class 2KB
ArticleDeleteAction.class 2KB
ImageCodeAction.class 2KB
AlbumServiceImpl.class 2KB
PhotoAddAction.class 2KB
ArticleAddAction.class 2KB
AlbumDetailAction.class 2KB
ArticleUpdateAction.class 2KB
Manager.class 2KB
MeServiceImpl.class 1KB
AlbumAddAction.class 1KB
ArticleRecommendAction.class 1KB
LoginInterceptor.class 1KB
ArticleDisRecommendAction.class 1KB
Me.class 1KB
CritiqueAddAction.class 1KB
CritiqueService.class 1KB
AlbumShowAction.class 1KB
ArticleService.class 1KB
MeUpdateAction.class 1KB
MeShowAction.class 1KB
CritiqueDeleteAction.class 1022B
AlbumDeleteAction.class 956B
PhotoDeleteAction.class 956B
BaseAction.class 924B
IOUtils$2.class 879B
IOUtils$4.class 638B
IOUtils$3.class 620B
IOUtils$1.class 616B
TimeUtil.class 591B
PhotoService.class 550B
AlbumService.class 395B
ManagerService.class 353B
MeService.class 276B
.classpath 668B
org.eclipse.wst.common.component 473B
org.eclipse.wst.jsdt.ui.superType.container 49B
editor_ie7.css 48KB
editor_iequirks.css 47KB
editor_ie8.css 46KB
editor_ie.css 46KB
editor_gecko.css 45KB
editor.css 45KB
dialog_ie7.css 17KB
dialog_ie8.css 16KB
dialog_iequirks.css 16KB
dialog_ie.css 16KB
dialog_opera.css 16KB
dialog.css 15KB
style.css 9KB
index.css 7KB
sample.css 5KB
media.css 3KB
base.css 2KB
outputxhtml.css 2KB
contents.css 2KB
about.css 2KB
templates.css 2KB
toolbar.css 1KB
wsc.css 1KB
sample.css 53B
outputforflash.fla 84KB
angel_smile.gif 1KB
devil_smile.gif 1KB
shades_smile.gif 1KB
angry_smile.gif 1KB
tounge_smile.gif 1KB
tongue_smile.gif 1KB
regular_smile.gif 1KB
wink_smile.gif 1KB
confused_smile.gif 1KB
teeth_smile.gif 1KB
omg_smile.gif 1KB
sad_smile.gif 1KB
whatchutalkingabout_smile.gif 1KB
broken_heart.gif 1KB
thumbs_down.gif 1KB
thumbs_up.gif 1KB
heart.gif 1KB
kiss.gif 1KB
lightbulb.gif 1KB
cry_smile.gif 795B
共 665 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
- TS古宁2019-04-29很是垃圾,垃圾垃圾
beiwulou2994
- 粉丝: 35
- 资源: 114
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功