ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi there
I have a directory with lot of files without any sub-folders, and i want to process in an easy was all the files in that folder. Can anyone suggest a way to do that in java. What ideally I want is a method like ls.
Hi again and thanks for your reply.
I would like for a second time to ask what can i do for getting the current path of the folder that I compile my Java files.
File current = new File (System.getProperty("user.dir"));
You can test with
System.out.println(file);
It's also a good idea to build in some extra code to verify whether your app isn't erroneously pointing to a non-existent path:
if (!current.exists()){
System.out.println("Directory not found");
System.exit(1);
}
will bring the application down without any ugly error messages if it fails to locate the required directory. You could also throw a FileNotFoundException but throwing exceptions tends to kill performance so the first approach should be preferred in most cases.
Thanks for your reply. I strongly believe that you can advise me on the following. Setting the case that there is a C program that can be executed with a Java Runtime command and its output in my case actually an Image, will be redirected back to the Java Program something like a scrollable Frame. Could you or anyone please recommend a way of doing that. I would also like to know if it is efficient.
So if I understand correctly, you want your application to call native i.e. compiled C code? If so, yes, that is possible through JNI. But it's not something that I would encourage you to dabble in while you're still learning the basics. For one thing because it adds a whole new level of complexity to the extent that you also need to be familiar with the fundamentals of C coding. For another because it can have some undesired restrictions. Applets, for example, can't access C code for security reasons. And bundling your applications with platform dependent calls inevitably means that you'll break portability; you would then need to recompile (and possibly rework) your C code for every targeted operating system.
Frankly, I'd much rather write a 100% java application if all I wanted to do is load an image. I remember writing a picture viewer on one occasion that was less than 100 lines of code. Sure, it was rather primitive but more than good enough. I think you may want to have a look at Java Swing if your need to learn about GUIs, buttons, icons, text and password fields, menus, scrollbars, what not.
Thanks for your reply. I strongly believe that you can advise me on the following. Setting the case that there is a C program that can be executed with a Java Runtime command and its output in my case actually an Image, will be redirected back to the Java Program something like a scrollable Frame. Could you or anyone please recommend a way of doing that. I would also like to know if it is efficient.
Thanks
Java can display pictures (not all formats) itself.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.