title: How to get a single file from a folder in java?
body: <p>The idea is to take one single file, but I don't want to list all of the files. I have the address of the specified folder, but not the name.</p>
  
  <p>Basically I want</p>
  
  <p>findFileInFolder(String folderName) --- this method returns a random filename or the oldest file created on the folder</p>
  
  <p>Has anybody ever tried doing this? Any ideas to avoid listing all of the files in an array and then taking the first one?</p>
  
  <hr>
  
  <p>Added:</p>
  
  <p>Just in case I wasn't clear (I'm really sorry for my English. Please forgive me if I sound prepotent or aggressive it is really not my intentions.) The file is not selected by a human, it's selected by the machine without asking or showing the file except for the method that returns a string with the FileName</p>
  
  <p>String findFileInFolder(String folderName)</p>
  
  <p>Like I comment is for usage of ram and processor because this is a secondary process and not the primary of the project, so if I have to read over a thousand files it will considerably reduce the performance of my project :(</p>
  
  <p>Thanks ;)</p>
  
  <hr>
  
  <p>Update: the program is running on different computers so if I could just access the directory not "thinking" about reading which file it would be great. =D</p>
  
  <hr>
  
  <p>Hopefully last update: sorry for bothering you guys :)</p>
  
  <p>From what I read on the answers there is no way. My question is: what good alternatives instead of doing an array would you think? My idea is to create an index in a textfile and to take only the first line.</p>