How to read data from text files:
==========================
package files;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class FileReadDemo {
public static void main(String[] args) throws IOException {
File file = new File("D:\\ramesh\\sampleproject\\src\\files\\abc.txt");
file.createNewFile();
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while(bufferedReader.ready())
{
System.out.println(bufferedReader.readLine());
}
}
}
==========================
package files;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class FileReadDemo {
public static void main(String[] args) throws IOException {
File file = new File("D:\\ramesh\\sampleproject\\src\\files\\abc.txt");
file.createNewFile();
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while(bufferedReader.ready())
{
System.out.println(bufferedReader.readLine());
}
}
}
No comments:
Post a Comment