Вот как я читаю файл с диска:
Обратите внимание, что весь код должен быть помещен в оператор try / catch, например, в случае FileNotFoundException.
try
{
//You first have to create a reader that will be used to access the file.
//You create the BufferedReader from a FileReader, and you only need to specify
//the address of the file on your disk.
BufferedReader br = new BufferedReader(new FileReader("fileURL"));
String s;
//The BufferedReader has a method "readLine" that reads the file line by line
//When the reader reaches the end of the file, the method readLine returns null,
//so you can control if there is some data remaining or not.
while( (s = br.readLine()) != null )
{
System.out.println(s);
}
//Don't forget to close the reader when the process is over.
br.close();
}
catch(Exception e)
{
// Do some stuff
}
Насколько я помню, классы BufferedReader и FileReader можно найти в пакете java.io;
На мой взгляд, это самый простой способ прочитать файл на Java. Если вам нужно знать, как написать файл, процесс почти такой же, поэтому я также могу дать вам несколько советов.
Надеюсь, это поможет.