Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1435

Re: Easy way to read the contants of a folder/directory and output contents to file?

From "Thee Chicago Wolf [MVP]" <.@.>
Newsgroups comp.lang.java.help
Subject Re: Easy way to read the contants of a folder/directory and output contents to file?
Date 2011-12-12 09:19 -0600
Organization .
Message-ID <pn6ce7tlo3qnhse1lnhs2k5mu4ae4dgjo3@4ax.com> (permalink)
References <e5rae71q7jppj0ms8jn0sc0qp636gn3csj@4ax.com> <8jgbe7hqkm4jg2mc7ns2j1jgvnmj82sfie@4ax.com>

Show all headers | View raw


>On Sun, 11 Dec 2011 21:06:38 -0600, "Thee Chicago Wolf (MVP)" <.@.>
>wrote, quoted or indirectly quoted someone who said :
>
>>Having a bit of trouble with the how-to of this. Say I want to read
>>the contents of a folder and then output the contents of the folder to
>>a file with each file name occupying its own line in the output file
>>as is shown below:
>
>File.list gets you an array of Strings with unqualified filenames.
>see http://mindprod.com/jgloss/filesanddirectories.html
>
>then a for:each loop through the array lets you get at each String.
>see http://mindprod.com/jgloss/jcheat.html#LOOPS
>
>Then just output that String to a PrintWriter.
>See http://mindprod.com/applet/fileio.html
>for sample code.

Thanks much for the links! I wound up doing what I needed with the
below code:

FileWriter folderOutput = new FileWriter("filelist.txt");
PrintWriter outFile = new PrintWriter(folderOutput);
for(int i = 0; i < list.length; i++)
{
outFile.write(String.valueOf(list[i]+"\n"));
}
folderOutput.close();

Now before you ask why I used .write instead of .println, it's because
when I use .println I get:

file1.txt
<space>
file2.txt
<space>
file3.txt
<space>
<space>

When I use .write, I get:

file1.txt
file2.txt
file3.txt
<space>

I've asked a few others as to why this would be. Do you have any idea?

cheers.

- Thee Chicago Wolf [MVP]

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf (MVP)" <.@.> - 2011-12-11 21:06 -0600
  Re: Easy way to read the contants of a folder/directory and output contents to file? "John B. Matthews" <nospam@nospam.invalid> - 2011-12-11 23:08 -0500
    Re: Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf [MVP]" <.@.> - 2011-12-12 08:42 -0600
      Re: Easy way to read the contants of a folder/directory and output contents to file? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-12-12 14:49 +0000
        Re: Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf [MVP]" <.@.> - 2011-12-12 09:12 -0600
          Re: Easy way to read the contants of a folder/directory and output contents to file? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-12-12 15:44 +0000
            Re: Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf [MVP]" <.@.> - 2011-12-12 09:51 -0600
      Re: Easy way to read the contants of a folder/directory and output contents to file? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-12 10:03 -0500
        Re: Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf [MVP]" <.@.> - 2011-12-12 09:15 -0600
          Re: Easy way to read the contants of a folder/directory and output contents to file? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-12 10:45 -0500
            Re: Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf [MVP]" <.@.> - 2011-12-12 09:52 -0600
  Re: Easy way to read the contants of a folder/directory and output contents to file? Roedy Green <see_website@mindprod.com.invalid> - 2011-12-12 01:02 -0800
    Re: Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf [MVP]" <.@.> - 2011-12-12 09:19 -0600
  Re: Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf [MVP]" <.@.> - 2011-12-12 09:08 -0600
    Re: Easy way to read the contants of a folder/directory and output contents to file? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2011-12-12 18:24 +0200
      Re: Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf [MVP]" <.@.> - 2011-12-12 10:54 -0600
        Re: Easy way to read the contants of a folder/directory and output contents to file? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-12 12:40 -0500
          Re: Easy way to read the contants of a folder/directory and output contents to file? "Thee Chicago Wolf [MVP]" <.@.> - 2011-12-12 12:03 -0600
          Re: Easy way to read the contants of a folder/directory and output contents to file? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-12 13:04 -0500

csiph-web