• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Searching for an image file

 
Greenhorn
Posts: 4
Eclipse IDE Firefox Browser Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want my java program to search for my image file and find the path to it. How do I do this? Please tell me whether there exists such a method so as to do this.
 
Ranch Hand
Posts: 62
5
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Venkat Natarajan wrote:I want my java program to search for my image file and find the path to it. How do I do this? Please tell me whether there exists such a method so as to do this.


If you mean to search a specific filename (or a more generic pattern, e.g. all .txt files) in one directory or in a directory tree, you have to use the list/listFiles methods in java.io.File class. It's not immediate .. these methods give you an array of String or File, you have to scan this array, verify each filename, etc... If you want to search on a tree of directories, you have to use recursion.

However, please clarify your final objective (in other words: why you are needing this).
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Venkat Natarajan wrote:I want my java program to search for my image file and find the path to it. How do I do this? Please tell me whether there exists such a method so as to do this.


As Andrea says, you need to specify exactly what you want. If it's by name, then there are lots of ways; if it's by content, then you'll probably to need to check by file size and then some form of checksum. You should be aware that the latter style doesn't guarantee a match, but the chances of finding one when files are not the same is extremely small.

Winston
 
Venkat Natarajan
Greenhorn
Posts: 4
Eclipse IDE Firefox Browser Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to run my program which is in the form of an exe in my friend's computer. I want to make such that the program will be able to access the images no matter where he saves it in his local disk.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please explain more. An exe file is unlikely to be a Java® file, and that may entail a security hazard.
 
Venkat Natarajan
Greenhorn
Posts: 4
Eclipse IDE Firefox Browser Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to search the file I want by name. For example, I want to obtain the path of an image called Dice.PNG without having to type it in myself. So I want to search by the string "Dice.PNG" to find the actual path of the image.
 
Andrea Binello
Ranch Hand
Posts: 62
5
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Venkat Natarajan wrote:I want to search the file I want by name. For example, I want to obtain the path of an image called Dice.PNG without having to type it in myself. So I want to search by the string "Dice.PNG" to find the actual path of the image.


And this concept is exactly what I have explained in my first answer. But you have to start somewhere, in one directory. It could be the "current" directory, the user "home" directory or the "root" of your filesystem. More files/directories to scan means more time ..... and it could be very long.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Venkat Natarajan wrote:I want to search the file I want by name.


In which case, you're simply searching for a file. The "image" business is completely irrelevant.

Winston
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In which case, you're simply searching for a file. The "image" business is completely irrelevant.


... in which case the next question would be: what does this program do that the search functionality built into the OS doesn't do?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic