2 Replies - 593 Views - Last Post: 07 March 2011 - 06:52 PM Rate Topic: -----

#1 jasperFernandes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 02-March 11

store text files into an array

Posted 07 March 2011 - 05:56 AM

hi, is it possible to create an array of text files. Lets say i got a set of 20 text files in a folder.
i would like to store those 20 text files into an array. Anyone advice on how to implement it ?
Is This A Good Question/Topic? 0
  • +

Replies To: store text files into an array

#2 Lovehandles  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-March 11

Re: store text files into an array

Posted 07 March 2011 - 07:13 AM

Try using the following code.
File folder = new File("T:/srcFolder");
File[] listOfFiles = folder.listFiles();
	
for (int i=0; i < listOfFiles.length; i++)
{
  if (listOfFiles[i].isFile())
  {
    System.out.println(listOfFiles[i].getName());
  }
}



The only thing you have to change is the folder name declared up top. Any questions on any of it?
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: store text files into an array

Posted 07 March 2011 - 06:52 PM

You can alternatively check for the file extension using the endsWith() method from the String class

if(listOfFiles[i].getName().endsWith(".txt"))
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1