捕获 InputStream 字符模式并将以下字符分配给 String

Capture InputStream character pattern and assign following characters to String

我有一个程序需要读取文件“FileToRead”中的特定 line/characters。该文件位于 File.trk 中,当转换为 File.zip 时会有其他文件夹和文件。

( File.trk 到 File.zip, File.zip 结构是 File.zip / FolderA / FolderB / FileToRead )

到目前为止,我已经能够将 File.trk 转换为 File.zip 并使用 ZipEntry 和 InputStream 将其转换为 FileToRead。我现在唯一的问题是如何从 InputStream 中捕获特定行或字符模式并将以下字符分配给 String?或者是否有更有效的方法来读取具有多个目录的 .zip 文件夹中的文件?

我知道 FileToRead 的内容,并且我只需要包含一个单词(一组字符)一次的特定行。

文件中的行:["DictKey_sortie_29"] = "Gauntlet"
文件中仅出现一次且始终相同的字词:“sortie”
想将“Gauntlet”设置为 String 变量。 (“Gauntlet”将始终更改为其他名称。)

    File trk = new File("C:\Path\File.trk");
    File zip = new File("C:\Path\File.zip");
    boolean success = trk.renameTo(zip);
    if (success) {
        ZipFile zipFile = new ZipFile(zip);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while(entries.hasMoreElements()){                                           
            ZipEntry entry = entries.nextElement();                                                                                                    
            if (entry.getName().contentEquals("FolderA/FolderB/FileToRead")) {
                InputStream stream = zipFile.getInputStream(entry);                    
                int content;
                while ((content = stream.read()) != -1) {
                    System.out.print((char)content);
                }
                stream.close();
            }
        }
    }

InputStreamReaderBufferedReader包裹zipFile.getInputStream(entry),然后逐行读取文件。

BufferedReader br = new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry)));
String line;
while ((line = br.readLine()) != null) {
  if (line.contains("sortie")) {
    //do your thing here
  }
}

完成后不要忘记关闭 BufferedReader。