<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'open directory and read all files' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'open directory and read all files' posted on the 'Java' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 05:07:52 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 05:07:52 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>open directory and read all files</title>
      <link>http://www.programmersheaven.com/mb/java/388352/388352/open-directory-and-read-all-files/</link>
      <description>hi,&lt;br /&gt;
i m very new in java. right now i m facing one problem to read many files from one folder. suppose i have few txt files in one folder and every txt files contain some my friends name.&lt;br /&gt;
&lt;br /&gt;
my program should open that folder and read all files one by one to find all friends name.&lt;br /&gt;
&lt;br /&gt;
so far i have done it from one particular txt file but i cant make it from many files within a folder.&lt;br /&gt;
&lt;br /&gt;
can anybody pls help me.....&lt;br /&gt;
1st code that i used to find from one particular file&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
FileReader fr;			BufferedReader br;
String result="";
String word= new String();
String target = "friend";


try{ //read one text file 
fr = new FileReader ("C:/Users/user/test/new1.txt");
br = new BufferedReader(fr);
Scanner scan = new Scanner(br); 

while(scan.hasNext()){  scan.next();
result = scan.findWithinHorizon(target,0); 

if(result!=null) {
word = (scan.next() + scan.findWithinHorizon("", 0));
    
  ArrayList&amp;lt;String&amp;gt; names = new ArrayList&amp;lt;String&amp;gt;();
names.add(word);
for (int i=0; i&amp;lt; names.size() ; i++) {
System.out.println(names.get(i));}

&lt;/pre&gt; &lt;br /&gt;
&lt;br /&gt;
2nd code where i m trying for many files, it has no errors but no output.&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
try{ //read files from folder 
File directory = new File("C:/Users/user/test");
String filename[] = directory.list();
	   
		 for (int i = 0; i &amp;lt; filename.length; i++) {
	
reader = new FileReader (filename[i])	;		
br = new BufferedReader(reader);
Scanner scan = new Scanner(reader); 

while(scan.hasNext()){  scan.next();
result = scan.findWithinHorizon(target,0); 

if(result!=null) {
word = (scan.next() + scan.findWithinHorizon("", 0));
  System.out.println(word);
    }
 
  }
 scan.close();
 }
}
catch(Exception e){ System.err.println(e.getMessage()); 
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/388352/388352/open-directory-and-read-all-files/</guid>
      <pubDate>Tue, 31 Mar 2009 08:34:52 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: open directory and read all files</title>
      <link>http://www.programmersheaven.com/mb/java/388352/388408/re-open-directory-and-read-all-files/#388408</link>
      <description>Comparing your code snippets maybe you need to use br instead reader in:&lt;br /&gt;
Scanner scan = new Scanner(reader); &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/388352/388408/re-open-directory-and-read-all-files/#388408</guid>
      <pubDate>Wed, 01 Apr 2009 05:45:31 -0700</pubDate>
      <category>Java</category>
    </item>
  </channel>
</rss>