package com.vsked.util;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class FileProcess {
public static void main(String[] args) throws Exception {
int bufSize=1024;
String ss="aabb天天第一\n";
ss+="资源类型:工具类\n";
ss+="654987351321\n";
ss+=" <html>\n";
ss+="<head>\n";
ss+="a\n";
ss+="b\n";
ss+="-->\n";
//writeFile("c:/ta.txt",ss);
//System.out.println(readFileByLine( new File("c:/ta.txt")));
List<FileInfo> a=readFileByLine( new File("c:/ta.txt"));
for(FileInfo f:a){
System.out.println(f.fileId+"_||||__"+f.fileName+"_||||__"+f.filePath+"_||||__"+f.fileSize+"_||||__"+f.lastModifyTime);
}
}
public static void writeFile(String saveFilePath,String fileContent) throws Exception {
ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
FileOutputStream outf = new FileOutputStream(saveFilePath);
FileChannel fc=outf.getChannel();
Charset cs = Charset.forName("utf-8");
for(int i=0;i<fileContent.length();i++){
buffer.put(new String(fileContent.charAt(i)+"").getBytes());
buffer.flip();
fc.write(buffer);
buffer.clear();
}
}
public static List<FileInfo> readFileByLine( File inF) throws Exception{
List<FileInfo> allFile=new ArrayList<FileInfo>();
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inF.getCanonicalPath())));
String data = null;
while((data = br.readLine())!=null)
{
data=data.replace("|", ",");
String[] s=data.split(",");
allFile.add(new FileInfo(s[0], s[1], s[2], s[3], s[4]));
}
return allFile;
}
public static boolean createFolder(String inFolderName){
File f= new File(inFolderName);
return ((!f.exists())&&(!f.isDirectory()))?f.mkdir():false;
}
public static void writeToFile(BufferedImage inputBufferedImage,String strFileFormat,File f) throws Exception{
ImageIO.write(inputBufferedImage, strFileFormat, f);
}
public static void writeJPEG(BufferedImage image, String path) throws Exception {
FileOutputStream out = new FileOutputStream(path);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
public static void writeToFile(RenderedImage inputRenderImage, String strImageFileExt, String inputPath) throws Exception{
FileOutputStream fos = new FileOutputStream(inputPath);
ImageIO.write(inputRenderImage, strImageFileExt, fos);
fos.flush();
fos.close();
}
public static String getFileChoosePath() throws Exception{
JFileChooser jc=new JFileChooser();
jc.showOpenDialog(null);
if(jc.getSelectedFile()!=null)
return jc.getSelectedFile().getCanonicalPath();
else
return "";
}
public static String get_charset(File file) throws Exception {
String charset = "GBK";
byte[] first3Bytes = new byte[3];
boolean checked = false;
BufferedInputStream bis = new BufferedInputStream( new FileInputStream( file ) );
bis.mark( 0 );
int read = bis.read( first3Bytes, 0, 3 );
if ( read == -1 ) return charset;
if ( first3Bytes[0] == (byte) 0xFF && first3Bytes[1] == (byte) 0xFE ) {
charset = "UTF-16LE";
checked = true;
}
else if ( first3Bytes[0] == (byte) 0xFE && first3Bytes[1] == (byte) 0xFF ) {
charset = "UTF-16BE";
checked = true;
}
else if ( first3Bytes[0] == (byte) 0xEF && first3Bytes[1] == (byte) 0xBB && first3Bytes[2] == (byte) 0xBF ) {
charset = "UTF-8";
checked = true;
}
bis.reset();
if ( !checked ) {
int loc = 0;
while ( (read = bis.read()) != -1 ) {
loc++;
if ( read >= 0xF0 ) break;
if ( 0x80 <= read && read <= 0xBF )
break;
if ( 0xC0 <= read && read <= 0xDF ) {
read = bis.read();
if ( 0x80 <= read && read <= 0xBF )
continue;
else break;
}
else if ( 0xE0 <= read && read <= 0xEF ) {
read = bis.read();
if ( 0x80 <= read && read <= 0xBF ) {
read = bis.read();
if ( 0x80 <= read && read <= 0xBF ) {
charset = "UTF-8";
break;
}
else break;
}
else break;
}
}
}
bis.close();
return charset;
}
}//end class FileProcess
没有合适的资源?快使用搜索试试~ 我知道了~
java版everything+纯java不用任何包读取office中word文件
共27个文件
class:13个
java:12个
project:1个
4星 · 超过85%的资源 需积分: 35 40 下载量 99 浏览量
2012-11-18
22:52:37
上传
评论 1
收藏 35KB ZIP 举报
温馨提示
原创资源物超所值.不使用任何jar包读取docx文件.Everything的java版本未完成但程序框架已经写出来了其中还包括java读取压缩文件解包压缩文件等各种文件操作类
资源推荐
资源详情
资源评论
收起资源包目录
vskeverything.zip (27个子文件)
vskeverything
.project 389B
bin
com
vsked
test
TestDirectory.class 2KB
everything
EverythingGUI.class 5KB
EverythingProcess.class 5KB
EverythingGUI$1.class 2KB
EverythingStateBar.class 549B
EverythingRightMenuAction.class 2KB
EverythingLanguage.class 1KB
FileListAction.class 3KB
util
OfficeTool.class 2KB
FileInfo.class 646B
VskTree.class 1KB
CompressFile.class 5KB
FileProcess.class 7KB
src
com
vsked
test
TestDirectory.java 1KB
everything
EverythingGUI.java 4KB
EverythingStateBar.java 234B
EverythingLanguage.java 589B
FileListAction.java 2KB
EverythingRightMenuAction.java 920B
EverythingProcess.java 4KB
util
FileProcess.java 6KB
VskTree.java 796B
OfficeTool.java 1KB
CompressFile.java 5KB
FileInfo.java 454B
.classpath 302B
共 27 条
- 1
vsked
- 粉丝: 32
- 资源: 117
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页