See lines:
System.out.println( "Can Read File: " + f.getName());
in the console, display: Can Read File:
www.tabledance.com.mx.url by sample but why not enter to the loop for display the content of the file??
thanks
Here the code:
import java.io.*;
public class listfi {
private static final
String REGQUERY_UTIL = "reg query ";
private static final String REGSTR_TOKEN = "REG_SZ";
private static final String COMPUTER_WINDOWS_FAVORITES_FOLDER = REGQUERY_UTIL +
"\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v Favorites";
public static String getCurrentPCFavorites()
{
try {
Process process = Runtime.getRuntime().exec(COMPUTER_WINDOWS_FAVORITES_FOLDER);
StreamReader reader = new StreamReader(process.getInputStream());
reader.start();
process.waitFor();
reader.join();
String result = reader.getResult();
int p = result.indexOf(REGSTR_TOKEN);
if (p == -1)
return null;
return result.substring(p + REGSTR_TOKEN.length()).trim();
}
catch (Exception e) {
return null;
}
}
static class StreamReader extends
Thread {
private InputStream is;
private StringWriter sw;
StreamReader(InputStream is) {
this.is = is;
sw = new StringWriter();
}
public void run() {
try {
int c;
while ((c = is.read()) != -1)
sw.write(c);
}
catch (IOException e) { ; }
}
String getResult() {
return sw.toString();
}
}
public static void main(String[] args)
{
// File directory = new File("C:\\Temp\\x");
// File directory = new File ( System.getProperty("user.home") + "/favorites");
File directory = new File ( getCurrentPCFavorites());
File[] filesInDir = directory.listFiles();
if (filesInDir != null) {
int length = filesInDir.length;
for (int i = 0; i < length; ++i)
{
File f = filesInDir[i];
if (f.isFile())
{
if ( f.canRead() )
{
System.out.println( "Can Read File: " + f.getName());
try
{
BufferedReader in = new BufferedReader(new FileReader(f.getName()));
String str;
while ((str = in.readLine()) != null)
{
System.out.println(str);
}
in.close();
}
catch (IOException e)
{
}
}
else
System.out.println( "Can NOT Read File: " + f.getName());
}
else if (f.isDirectory())
{
System.out.println( "Directory: " + f.getName());
}
}
}
}
}