相关疑难解决方法(0)

从Zip文件中的文件中读取内容

我正在尝试创建一个简单的java程序,它从zip文件中的文件中读取和提取内容.Zip文件包含3个文件(txt,pdf,docx).我需要阅读所有这些文件的内容,我正在使用Apache Tika.

有人可以帮我在这里实现功能.到目前为止我尝试过这个但没有成功

代码片段

public class SampleZipExtract {


    public static void main(String[] args) {

        List<String> tempString = new ArrayList<String>();
        StringBuffer sbf = new StringBuffer();

        File file = new File("C:\\Users\\xxx\\Desktop\\abc.zip");
        InputStream input;
        try {

          input = new FileInputStream(file);
          ZipInputStream zip = new ZipInputStream(input);
          ZipEntry entry = zip.getNextEntry();

          BodyContentHandler textHandler = new BodyContentHandler();
          Metadata metadata = new Metadata();

          Parser parser = new AutoDetectParser();

          while (entry!= null){

                if(entry.getName().endsWith(".txt") || 
                           entry.getName().endsWith(".pdf")||
                           entry.getName().endsWith(".docx")){
              System.out.println("entry=" + entry.getName() + " " + entry.getSize());
                     parser.parse(input, textHandler, …
Run Code Online (Sandbox Code Playgroud)

java zip extract apache-tika

62
推荐指数
3
解决办法
14万
查看次数

用于从压缩文本文件中获取文本行的阅读器

摘要:有了contains的字节图像,我怎样才能获得一个干净且正确的读取器来返回文本文件的行?a.zipa.txt

我确实将 zip 文件的图像从 Web 服务下载到byte[] content. 我想写一个类似的方法

private BufferedReader contentToBufferedReader(byte[] content)
Run Code Online (Sandbox Code Playgroud)

这将返回一个可以像这样使用的读者

reader = contentToBufferedReader(content);
while ((line = reader.readLine()) != null) {
    processThe(line);
}
reader.close()
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经(更新

private BufferedReader contentToBufferedReader(byte[] content) {

    ByteArrayInputStream bais = new ByteArrayInputStream(content);
    ZipInputStream zipStream = new ZipInputStream(bais);
    BufferedReader reader = null;

    try {
        ZipEntry entry = zipStream.getNextEntry();

        // I need only the first (and the only) entry from the zip file.
        if (entry != null) { …
Run Code Online (Sandbox Code Playgroud)

java zip android inputstream bufferedreader

5
推荐指数
1
解决办法
7713
查看次数

java.util.zip.ZipException:无效的条目压缩大小(预期为 449,但得到 455 个字节)

将文件从一个 zipfile 子文件夹复制到另一个 zipfile 子文件夹。version并且folder是从前端获取的子文件夹名称。

public String restore(String jobId, String version, String folder) {
    String fileName = String.valueOf(jobId) + ".zip";
    String versions[] = version.replaceAll("'", "")
        .replace("[", "")
        .replace("]", "")
        .split(",");
    String folders[] = folder.replaceAll("'", "").replace("[", "").replace("]", "").split(",");
    ArrayList<String> listofVersion, listofFolder = new ArrayList<>();

    File destinationFile = new File(env.getProperty("file.path") + fileName);
    File sourceFile = new File(env.getProperty("file.arcivePath") + fileName);

    FileInputStream in;
    FileOutputStream out;
    ZipInputStream zin;
    ZipOutputStream zipout;
    int BUFFER = (int) sourceFile.length();

    if (!destinationFile.exists()) {
        try {
            out …
Run Code Online (Sandbox Code Playgroud)

java zip file unzip

2
推荐指数
2
解决办法
9756
查看次数

标签 统计

java ×3

zip ×3

android ×1

apache-tika ×1

bufferedreader ×1

extract ×1

file ×1

inputstream ×1

unzip ×1