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]);
		}
		
		
	}

}

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();

Splendid!

thanks for fast reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.