• Post Reply Bookmark Topic Watch Topic
  • New Topic

Searching for an image file  RSS feed

 
Greenhorn
Posts: 4
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • 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: 56603
172
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 42972
73
  • Mark post as helpful
  • send pies
  • 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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!