- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
File tarFile = new File(UUID.randomUUID() + ".tar");
tarFile.createNewFile();
FileOutputStream tarFileOutputStream = new FileOutputStream(tarFile.getAbsolutePath());
TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(tarFileOutputStream);
String entryName = "пример.txt";
File fileToPack = new File("C:\\пример.txt");
InputStream in = new FileInputStream(fileToPack);
//создаем запись в архиве с русским названием
TarArchiveEntry entry = new TarArchiveEntry(entryName);
entry.setSize(in.available());
archiveOutputStream.putArchiveEntry(entry);
while (in.available() > 10 * 1024 * 1024) {
byte b[] = new byte[10 * 1024 * 1024];
in.read(b);
archiveOutputStream.write(b, 0, b.length);
}
byte b[] = new byte[in.available()];
in.read(b);
archiveOutputStream.write(b, 0, b.length);
in.close();
archiveOutputStream.flush();
archiveOutputStream.closeArchiveEntry();
archiveOutputStream.flush();
archiveOutputStream.close();