日期:2014-05-17  浏览次数:20684 次

各位大牛啊,谁用过at4j啊,那个directory是怎么构造出来的啊
用at4j来打包文件夹,需要创建archive,但是sample中默认的有个directoryView的targetDir,哭了,在线等,谢谢

------解决方案--------------------
直接贴代码,at4j实现java tar打包,打包后中文文件名不会乱码。百度了下没人解决。贴出来下。
参考http://entityfs.org/ 和 http://www.at4j.org/
directoryView 是 entityfs 啥文件系统弄出来的。还是google好用。 

先建好下面两个
E:/A/中文.txt
E:/B

运行完E:/B/myArchive.tar就出来了。

package at4j;

import java.io.File;
import java.nio.charset.Charset;

import org.at4j.tar.builder.GnuTarEntryStrategy;
import org.at4j.tar.builder.TarBuilder;
import org.at4j.tar.builder.TarBuilderSettings;
import org.at4j.tar.builder.TarEntrySettings;
import org.entityfs.FileSystem;
import org.entityfs.RandomlyAccessibleFile;
import org.entityfs.el.AbsoluteLocation;
import org.entityfs.fs.FSRWFileSystemBuilder;
import org.entityfs.util.Directories;


public class TarDemo {

/**
* @param args
* @throws Exception 
*/
public static void main(String[] args) throws Exception {

FileSystem srcFS = new FSRWFileSystemBuilder().setName("FSRWFileSystem").setRoot(new File("E:/A")).create();
FileSystem destFS = new FSRWFileSystemBuilder().setName("FSRWFileSystem").setRoot(new File("E:/B")).create();

RandomlyAccessibleFile tarFile = Directories.newFile(destFS.getRootDirectory(), "myArchive.tar");

TarBuilderSettings settings = new TarBuilderSettings().setDefaultFileEntrySettings(
new TarEntrySettings()).setDefaultDirectoryEntrySettings(
new TarEntrySettings()).setEntryStrategy(new GnuTarEntryStrategy(Charset.forName("GBK")));

TarBuilder builder = new TarBuilder(tarFile, settings);
builder.addRecursively(srcFS.getRootDirectory(), new AbsoluteLocation("/"));
builder.close();

}
}