का उपयोग कर एक टीएआर फ़ाइल को कैसे खोलें I ".tar.gz"
फ़ाइलों को संकुचित और असम्पीडित करने के लिए अपाचे कॉमन्स 1.4.1 लाइब्रेरी का उपयोग कर रहा हूं।अपाचे कॉमन्स
मुझे अंतिम बिट में परेशानी हो रही है - TarArchiveInputStream
को FileOutputStream
में परिवर्तित करना।
अजीब तरह से पर्याप्त है, यह इस लाइन पर तोड़ रहा है: C:
FileOutputStream fout = new FileOutputStream(destPath);
destPath
की एक विहित पथ के साथ एक फ़ाइल है \ दस्तावेज़ और \ My Documents सेटिंग्स \ प्रशासक \ JavaWorkspace \ BackupUtility \ untarred \ टेस्ट \ subdir \ testinsub.txt
त्रुटि का उत्पादन:
Exception in thread "main" java.io.IOException: The system cannot find the path specified
कोई विचार यह क्या हो सकता है? और यह पथ खोजने में सक्षम क्यों नहीं है?
मैं नीचे दी गई पूरी विधि को जोड़ रहा हूं (जिनमें से अधिकांश here से उठाया गया है)।
private void untar(File dest) throws IOException {
dest.mkdir();
TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
// tarIn is a TarArchiveInputStream
while (tarEntry != null) {// create a file with the same name as the tarEntry
File destPath = new File(dest.toString() + System.getProperty("file.separator") + tarEntry.getName());
System.out.println("working: " + destPath.getCanonicalPath());
if (tarEntry.isDirectory()) {
destPath.mkdirs();
} else {
destPath.createNewFile();
FileOutputStream fout = new FileOutputStream(destPath);
tarIn.read(new byte[(int) tarEntry.getSize()]);
fout.close();
}
tarEntry = tarIn.getNextTarEntry();
}
tarIn.close();
}
यह पूछने के लिए शर्मिंदा है, लेकिन मैंने आपके कोड नमूने का उपयोग करने की कोशिश की और इसे एक विशेष 'gzip' फ़ाइल' के साथ काम करने के लिए देखा जो मैं काम कर रहा था। यह इनपुटस्ट्रीम पर पढ़ने वाली सामग्री को देखते हुए 'fout.write (...) 'के किसी भी कॉल के बिना कैसे काम करता है? [Answer @ user1894600 सुझाता है] में (http://stackoverflow.com/a/14211580/320399), उसे स्पष्ट रूप से 'लिखना (...)' कॉल करना होगा और बाइट सरणी प्रदान करना होगा जिसे स्मृति में पढ़ा गया है। – blong