I need to create a service that finds specific folders and archives them into on zip file.
I saw all kind of examples, but it seems that have to read all the files in every folder. Am I right?
Is there another way to do that (maybe using truezip for that matter)?
I want to use truezip since I understood you could easily add files/folders to a zip file.
I've searched for a simple example of archiving a folder using truezip - but I couldn't find anything useful - I need a simple example of how to archive a given folder.
I'm using Java 6. How to archive a folder in Java using truezip?
EDIT:
Also found this example.
Using TrueZIP, all you need to call is
new TFile("folder").cp_rp(new TFile("archive.zip"));
I suggest to read it's tutorial in order to get a better understanding of what it all means: TrueZIP Tutorial
Related
I am trying to download jsoup under the following link: https://jsoup.org/download but I am not sure where to save this in my library... Can someone help please!
Typically, things like that come in a JAR file, which is a fancy ZIP file for Java. All your JAR have to listed on the classpath. There are different conventions for where to put your JAR, but, for a simple app, they can be in the root directory of your classes.
I have developed an application that basically searches its resources/runtime directory, looking for .java files.
Having fetched all .java sources, it (together with program arguments) passes their absolute paths to JavaCompiler.
Of course, this approach doesn't work when application is deployed as a JAR package. So the question - how can I work with resource files as with regular files, i.e. pass their absolute path and read them afterwards?
I found some related topics here:
reading the file as a stream
making a resource copy to some temporary file
But what if I don't know names of the files? I seek solution that allows me to search the resources/runtime directory. Moreover, I think making a copy of file somewhere and delete it later on is clumsy solution.
I use combination of Java and Scala (with sbt build system), hence solution Java or Scala would be great.
I have started getting into game programming.
My question is, that when I am working with files, either parsing data, writing to files, etc. Should I be using relative path names, or absolute pathnames, or something else which is better. I've heard about using jar files, but I am not sure
1. how that works
2. if it is a good way to do it.
So when developing a game that will be cross platform, what is the best method for managing files that the program will need to read from and write to.
there are several ways in which you can ship your code as a product. the most common are
packaging everything in one executable jar file.
having a set of folders where you place all necessary resources.
minecraft, for example, is written in java and distributed as a single executable jar file that contains all necessary class files and resources. to run the game (assuming you have java installed) all you need to do is double-click the jar file.
read this short tutorial about how to add a main class to a jar file.
either way, always treat classes and resources in your code as if they're in your classpath. for example, if you have a my.properties file on the root of the source tree then load it by using 'my.properties'. if you put it under a 'conf' folder then use 'conf/my.properties'.
i think it is the safest way not to get lost.
are you using maven?
The jar file is a zip of all your compiled *.class files and your resources. You can safely load your resources and even default data FROM a jar if you package your program, but you can NOT safely write data back to the jar. This detail is answered in depth already at
How can an app use files inside the JAR for read and write?
For information on how to package a jar see
http://docs.oracle.com/javase/tutorial/deployment/jar/
I am trying to write a program in Java, which would collect a specified set of files from the physical location and place them in a jar in a certain directory.
I know I can use java.util.jar package for this. The package is great for sure, but I was wondering if there are any third party libraries that anyone at SO has used which they could recommend.
TL;DR: pick up files, create jar by placing them in pre-defined directories, all at run time in a java file.
P.S: I did not find any similar references to this question, but if there are then please refer me. Also, the title might be misleading, but I didn't find better words to explain my problem.
EDIT 1: I am not in anyway saying java.util.jar is bad or incomplete. All I am asking is if anyone has used any alternative solutions!
EDIT 2: I am trying to create the jar from inside the java program. The jar can be pretty big (~500mb) too. Trying to jar media files as well. So simply put, I pick up various files from certain locations on my drive and try to create a jar file by placing them in standard locations.
Thanks,
Ivar
Look at the java.util.zip package. Jars are just zip files with some extra stuff in 'em
I'm working on a java android project. this project requires to use specific commands.
these commands are all developed in c++/c but I've been given two files (.jar and .so) that are supposed to "turn them into" java, so I can use them in my java android project.
The thing is, what am I supposed to do with these 2 files?? I've read a lot of stuff (mostly about creating the .jar and .so, but I don't care about this step, for I already have the 2 files)
I tried to import the .jar (import external lib), I tried to add the .so via the static loading :
//static {
// System.loadLibrary("MySoFile");
// }
All I get is a stack overflow error or a problem with the DEX file...
Has anybody ever tried to do this??
I don't seem to get the point here...all I want to do is being able to use the commands in the .jar file.... ://
thanks in advance!!
Take a look at this answer about adding jar files. '.so' files can usually just be drag and dropped to the project.
All you need to do is make sure the jar is in your classpath and you can then access the classes within this jar. A jar is just an archive of classes, you don't need to load the library into memory or something similar.
You may want to read the answer to the question here How to use classes from .jar files?