// get list of selected files
File[] file = jfc.getSelectedFiles();
String s=""; int c=0;
for(int i=0;i<file.length;i++) //added
{
// The toString will just return you back the path of the file object times the number of bytes in the file.
jep.setText(file[i].toString()); // added
}
return FileData;
Этот код не будет работать.Если вы хотите, чтобы метод считывал файл с заданным именем в массив строк, вам потребуется:
/**
* Read entire contents of a text file.
*
* @param fileName Text file name
* @return ArrayList of String (line) elements
* @throws FileNotFoundException
* @throws IOException
*/
public static ArrayList readTextFile( String fileName )
throws FileNotFoundException, IOException
{
ArrayList lines = new ArrayList();
BufferedReader in = null;
try
{
in = new BufferedReader( new FileReader( fileName ));
String line;
while ( ( line = in.readLine()) != null )
{
lines.add( line );
}
}
finally
{
if ( in != null )
{
try
{
in.close();
}
catch ( IOException ex )
{
}
}
}
return lines;
}
Поскольку вы хотите прочитать содержимое нескольких файлов, просто сделайте это в циклеи делать каждый в отдельности.Если вы загрузите все это в память, у вас могут возникнуть проблемы.