次のようにできます。
public String [] readFile(String filePath){
String [] lines=new String[1000];//Enough lines.
int counter=0;
try{
File file = new File(filePath);//The path of the File
FileReader fileReader1 = new FileReader(file);
BufferedReader buffer = new BufferedReader(fileReader1);
boolean flag=true;
while(true){
try{
lines[counter]=buffer.readLine();//Store a line in the array.
if(lines[counter]==null){//If there isn't any more lines.
buffer.close();
fileReader1.close();
break;//Stop reading and close the readers.
}
counter++;
}catch(Exception ex){
break;
}
}
}catch(FileNotFoundException ex){
System.out.println("File not found.");
}catch(IOException ex){
System.out.println("Exception ocurred.");
}
return lines;
}
または単なる別の例。
List<string> s = new List<string>();
s.Add("c:\\documents and settings\\sound1.mp3");
s.Add("c:\\documents and settings\\sound2.mp3");
var mp3paths = s.Where(x => String.Compare(".mp3", Path.GetExtension(x), true) == 0);
var exepaths = s.Where(x => String.Compare(".exe", Path.GetExtension(x), true) == 0);
お役に立てれば。