I am trying to read and parsed all the CSV files, these files are inside of extracted zip file, but unfortunately, I'm only getting this (No such file or directory) - How can I get inside that folder and read those files? Take note that this folder is already unzipped.
I'm also thinking, that if that is not possible - is there any way that I can extract the zip file to files only, for example below:
Zip File: ZipFolder.zip
Expected: (No folder at all, automatically the files is on the target location already).
CSVFile1.csv
CSVFile2.csv
Can someone help me to get through this? your help is appreaciated.. Thank you!
Related
I have stored blobs of multiple files in the database. User should be able to click on a link and should be able to download all the files as zipped. But before that I want to provide a folder structure to group those files. Say, a base folder followed by nested folders and related files. I followed the link below, looks like, I need to first create a physical dir structure for the same and then zip that structure?
http://www.journaldev.com/957/java-zip-example-to-zip-single-file-and-a-directory-recursively
Files in a zip directory are abstracted as ZipEntry objects in Java. Those have names that corresponds to the path relative to the directory where you unpack the zip file. Directories in a zip file are simply entries whose name ends with /. This way, you can also view a zip file as a plain list of binary data entries whose names reflect the directory structure.
So you don't have to create a folder structure on you hard drive and zip it but you can write directly from the database to the ZipOutputStream:
Create each folder as a ZipEntry with no content and a name ending with /.
Instead of using a FileInputStream for reading from files on the hard drive, write the output of resultSet.getBinaryStream("blobcolumn") directly to the entry.
I am having problem to use JWNL wordnet in a Jar file.
JWNL uses RandomAccessFile to read wordnet dictionary files. In order to create a Jar file, wordnet dictionary files are put in resources/wordnet folder. As resources is in my Build Path, I have no problem to run the application I created in Eclipse. However, when I use another application to run the created jar file, I get the following error:
java.io.FileNotFoundException: resources/wordnet/data.noun (No such file or directory)
from the following code:
RandomAccess _file = new RandomAccessFile(path, _permissions);
I use the following code to check the current working directory:
URL location = PrincetonRandomAccessDictionaryFile.class.getProtectionDomain().getCodeSource().getLocation();
System.out.println(location.getFile());
It seems both situation have the same location: /project/bin/
How should I fix the problem? Thank you
The key information you seem to be missing is that Jar files are compressed, and you can't "seek" because of the compression (which is I believe the DEFLATE algorithm).
However, you could extract the file(s) into temp file(s) on start and then use that. Temp files would be removed on application exit, and are the best answer I can think of.
RandomAccessFile to read files in a Jar file
There are no files in a JAR file. There are JAR entries. You can't read them with FileInputStreams, RandomAccessFiles, or FileReaders.You need to use a JarInputStream or its friends.
I would like to get a list of file contained in a directory which is in a jar package.
I have an "images" folder, within it I have an Images class that should load all images from that directory.
In the past i used the MyClass.class.getResourceAsStream("filename"); to read files, but how do I read a directory?
This is what I tried:
System.out.println(Images.class.getResource("").getPath());
System.out.println(new File(Images.class.getResource("").getPath()).listFiles());
I tried with Images.class.getResource because I have to work with File and there isn't a constructor that accepts an InputStream.
The code produces
file:/home/k55/Java/MyApp/dist/Package.jar!/MyApp/images/
null
So it is finding the folder which I want to list files from, but it is not able to list files.
I've read on other forums that in fact you can't use this method for folders in a jar archive, so how can I accomplish this?
Update: if possible, i would like to read files without having to use the ZipInputStream
You can't do that easily.
What you need to do:
Get the path of the jar file.
Images.class.getResource("/something/that/exists").getPath()
Strip "!/something/that/exists".
Use Zip File System to browse the Jar file.
It's a little bit of hacking.
I can create a jar using
http://www.java2s.com/Code/Java/File-Input-Output/CreateJarfile.htm
I want to create a zip file. The zip file should have a folder "test" and put the jar inside folder "test". How can I do? any snippets for this.
You can find it.It is very Useful link you can provide a zar file for zip file.Suppose you have a abc(zar file) and test is zip folder name.Then in this link code is given so somewhere you can find file file1,file2,there you can provide your file abc
ZarInsideZip
I have a series of zip files and I want to add their contents to another zip file. How could I do this without extracting? I can't extract a file inside one of the zips because it is called aux.class, which cannot be made on Windows.
The problem is, Zip files weren't designed to be appended to.
What I would try and do is
Create a new zip file
Read the contents of each existing file, writing the contents of the stream to the new zip file
Rename/delete the old zip (the one you are trying to "append")
Rename the we zip ino it's place
You could have a look at Compressing and Decompressing Data Using Java APIs for some ideas