I have combined two files in android, using this Linux command
cat file1.png file2.zip > file3.png
How can I split two files again?I just want the zip file to be retrieved separately.
Is there any specific command?I've tried these codes:
unzip file3.png
Replaced png with zip:
unzip file3.zip
but none of them work.
The only application with which I can open the combination, is winrar on windows
And also I tried several unzipping and unraring apps on android but none of them work except RAR app by rarlab
Is there any source for those apps I mentioned to unrar/unzip the file?
Strictly speaking : there's no way.
You might look for the PK 0x04 0x03 as a separator in the answer above, but you don't have any guaranty that this char sequence does not show up in the image data of the file1.png as well.
All together it's a funny question. If you want to split files like this on a regular basis rethink your strategy. If you need it to correct a one time mistake or something, you can split finding the seperator and be ok in over 99% of the cases.
What you need to know is that PNG files start with the hex value 0x89 followed by the text PNG. Zip files start with PK 0x04 0x03. You could write a utility which reads a file and outputs the bytes read in to a new file, using a new output file when a certain file signature is detected.
For a one-of solution, you can use vim, though you have to be careful to stop vim from adding a newline character to the end of the line.
Copy your input file for safety
cp file3.png f1
cp file3.png f2
vim -b f1
and in vim type
:set noeol
search for the start of the zip file
/PK
checking that the sequence found is PK^C^D. If not, look for the next match.
Delete the end of the line from PK with
d$
Move down a line, delete the remainder of the file and save
j
:.,$ d
ZZ
Similarly, delete the top of the file in f2 to get the zip file.
Note: don't name f2 as f2.zip because vim is smart enough to open this as as a zip file, which is not what you want here.
I'm not sure what you trying to accomplish by "hiding" a zip file into a PNG, but if you are trying to make a single file Winrar can open, then that's an odd way to do it.
You do not make a .zip (or any other type of archive) file when you cat a file to the either the start or end of a zip file. That simply appends two binary files together.
The reason winrar can open your "combined" binary file is that it most likely recognizes the file headers and can decipher you have 2 files.
I suggest you look into the usage of the zip command, for how to add files to an archive. I quick search shows, for example
zip -rv zipfile.zip newfile.txt
Will add newfile.txt to zipfile.zip.
Related
We have zip archives on our server that contain .csv files. If requested, we want to deliver those files as .xlsx within a newly created archive. I have already written the code to do the conversion using apache-poi and am having trouble asserting the results during testing.
In my test, I have one input zip file that contains a .csv. I run the test once and store the result of the conversion as a zip file (to use it as the expected output afterwards). I understand that comparing the resulting zip archives directly is not possible, so I unpack them, read all bytes of each file in both folders and compare them with Assertions.assertArrayEquals. This is where I run into trouble. Here and there, the arrays are off in both length and content.
Can anyone tell me why that is? When I look at the actual files, they are the same and how they should look like after conversion.
I have a directory containing both Zip & Rar archives.
I already have a way to get a zip file's comment -
if (f.getName().substring(f.getName().length() - 3).equals("zip")) {
ZipFile zip = new ZipFile(f);
zip.getComment();
}
Is there a way to do the same thing on a Rar file?
note that:
There are too many rar files for me to manually convert them to zip on some site (If there is some script to convert them, it could work).
Renaming a rar file's extension to .zip (file.rar -> file.zip) would still produce an exception when trying to create a new ZipFile object with it.
Thanks in advance!
I think in the end, you are looking for some sort of library to get that done for you. Like raroscope or java-unrar.
Alternatively, you could decide to re-invent that wheel yourself (not recommended).
Or you simply run the command line rar tool using ProcessBuilder (as a system command), like explained here.
I have a project with around 50 java classes/files (this 50 files includes both JSP and Java files). In this files I have written code to display abc.jpg image on my JSP pages. Now I want to write a java program which will replace all the abc.jpg images by xyz.jpg image in my project. I have no clue how I can do this. Also suggest if there is any free tool available to do the same.
What you want to do, will be done using following steps. Please note that you can find information about each step in StackOverflow itself in different posts:
1. Create a traversal policy for a directory in which all files are present, to get path of all .java and .jsp files.
2. Read all files one-by-one and write its content to another temporary file line by line.
3. While reading individual line, check whether it contains the name of .jpg file whose name you want to update. If yes the replace the name with new name and write the current updated line in temporary file.
4. Once the file reading is completed, delete the original file and rename the temporary file to original one.
5. Now you will have a same file with updated names of .jpg files.
6. Repeat the steps from 2-5 until all files are read and write.
Hope this will help. And yes you have to search these methods in SO itself. :-)
ZIP entries store the full path name of the entry because (I'm sure of the next part) the ZIP archive is not organized as directories. The metadata contains the info about how files are supposed to be stored (inside directories).
If I create a ZIP file in Windows, when I unzip the data in another OS, e.g. Mac OS X, the file structure remains as it used to be in Windows. Is this because the unzipper is designed to handle this, or isit because the file separators inside the ZIP are standard?
I'm asking this because I'm trying to find an entry inside a ZIP file using the name of the zipped file. But which file separator should I use to make it work in systems other than Windows?
I'm using Java, and the method: .getName() of the ZipEntry gives me the path using the Windows file separator \. Would it be enough if I use the java File.separator separator to make it work on another OS? Or will I have to try to find my file with each possible separator?
Honorary Correct Answer Mention
The answer given by #Eren Yilmaz is correct describing the functionality of many tools (or even the one you can code yourself). But given that the .zip standard clearly documents how it must be, the correct answer had to be updated
The .zip file specification states:
4.4.17.1 The name of the file, with optional relative path.
The path stored MUST not contain a drive or
device letter, or a leading slash. All slashes
MUST be forward slashes '/' as opposed to
backwards slashes '\' for compatibility with Amiga
and UNIX file systems etc. If input came from standard
input, there is no file name field.
The file separator is dependent on the application that creates the zip file. Some applications use the system file separator, whereas some use the "civilized" forward slash "/". So, if you are creating the zip file and then consuming it, then you can simply use a forward slash as file separator. If the zip file is created on somewhere else, then you should find out which separator was used. I don't know a simple way, but you can use a brute method and check out both separator types as you progress.
Some applications, especially custom zip creation codes, can mix the separators on different zip entries, so don't forget to check out each entry.
I've never seen that,internally generated?How does it work?
Can check what I meen here:
http://issues.apache.org/jira/secure/attachment/12401970/nutch_0.9_OR.patch
search "java~"
and you can see "java.old" there,what's that again?
It's probably some cruft leftover from emacs. With emacs, whenever you save a file, it saves a backup of the previous version of the file, and the backup is named with the original filename with a tilde appended to it. If this is the case (which you can easily verify by comparing file with file~), then you can safely ignore all of the files named with tildes.
Are you sure its generated from some java process? ~ in files typically means a temporary file created by editors, such as vim when you modify something.