服用下列的範例, 可以讀出文字檔的內容為字串.
File file = new File(your_file_path);
BufferedReader br;
String content = "";
try
{
br = new BufferedReader(new FileReader(file));
String st;
try
{
while ((st = br.readLine()) != null)
{
System.out.println(st);
content += st;
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
return content;