0

Hello there
I am new to my coding career :) and have been facing a slight problem over here
I want to read a folder\s files and have tried countless ways of accessing the directory but keep getting my code's error message. Please have a look and guide me if possible.
Thanks in advance

import java.io.File;


public class Reader 
{
	int fileslist[];
	File directoryOfTxts = new File("/Users/admin/Documents/workspace/SearchEngine2/src/inputFiles/");
	{
		if(directoryOfTxts.exists())
		{
			System.out.println(directoryOfTxts.getName() + "as provided folder is valid");
			String fileslist[] = directoryOfTxts.list();
		}
		else 
			System.out.println("Invalid provided directory");
		
		System.out.println("Id\tName");
		for(int counter=0; counter<fileslist.length; counter++)
		{
			System.out.println(counter + "\t" + fileslist[counter]);
		}
		
		
	}

}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by hatux
0

1. Your code isn't in a method. Try putting it in a main method.
2. You have the array fileslist declared twice: on lines 6 and 12. Change the declaration on line 6 to

String fileslist[] = null;

and change line 12 to this:

fileslist = directoryOfTxts.list();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.