0

Actually i'm using a method to zip a generated txt file in my android app, in the following txt file there are data separed by enter like

123213213
123213132
424242244

But if i zip this file and unzip it on my computer the following file will be

123213213□123213132□424242244

Here is the method that i'm using to zip the file

public void zip(String files, String zipFile) throws IOException {
    BufferedInputStream origin;
    try (ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)))) {
        byte[] data = new byte[BUFFER_SIZE];

        FileInputStream fi = new FileInputStream(files);
        origin = new BufferedInputStream(fi, BUFFER_SIZE);
        try {
            ZipEntry entry = new ZipEntry(files.substring(files.lastIndexOf("/") + 1));
            out.putNextEntry(entry);
            int count;
            while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
                out.write(data, 0, count);
            }
        } finally {
            origin.close();
        }
    }
}
NiceToMytyuk
  • 3,644
  • 3
  • 39
  • 100
  • Let me guess, you use Windows on your computer? :) – Sergey Glotov May 17 '19 at 14:29
  • Android as Linux-based system uses LF as newline character. Some Windows programs doesn't recognize this symbol as a newline (Windows uses CR+LF) – Sergey Glotov May 17 '19 at 14:32
  • @SergeyGlotov exactly i have Windows on the computer, so is there any way to transform that LF to CR+LF? – NiceToMytyuk May 17 '19 at 14:33
  • 1
    1. If text file is generated by your application, and you need Windows compatible text files, you can use "\r\n" in the end of strings instead of just "\n". 2. Do nothing :) You can try to use another program to open text files. AFAIK, WordPad handles it correctly. – Sergey Glotov May 17 '19 at 14:38
  • 1
    @SergeyGlotov i'm going to try "\r\n" immediatly, i can't use a different text editor as the file is sent on our client server and by an automatic management system is inserted in a database and with "LF" it have different "bytes" i think and just set the file as invalid – NiceToMytyuk May 17 '19 at 14:40
  • How is it going? – Sergey Glotov May 19 '19 at 19:40
  • @SergeyGlotov that was it, if you want make an answer so i'd able to accept it. – NiceToMytyuk May 20 '19 at 13:50

0 Answers0