Learn Java Tutorial for Beginners, Part 37: Reading Text Files

preview_player
Показать описание
In this video by Quordnet Academy for the series Learn Java Tutorial for Beginners how to use Read Text Files have been discussed.
If you would like to discover even more about java programming tutorial or the java complete course I advise you to check out the playlist :

Different ways of Reading a text file in Java
There are multiple ways of writing and reading a text file. this is required while dealing with many applications.

There are several ways to read a plain text file in Java e.g. you can use FileReader, BufferedReader or Scanner to read a text file. Every utility provides something special e.g. BufferedReader provides buffering of data for fast reading, and Scanner provides parsing ability.

Here are some of the many ways of reading files:
Using BufferedReader: This method reads text from a character-input stream. It does buffering for efficient reading of characters, arrays, and lines.
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.
In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,

BufferedReader in = new BufferedReader(Reader in, int size);
Using FileReader class: Convenience class for reading character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are appropriate.
Constructors defined in this class are:
// Creates a new FileReader, given the
// File to read from.
FileReader(File file)

// Creates a new FileReader, given the
// FileDescriptor to read from.
FileReader(FileDescriptor fd)

// Creates a new FileReader, given the
// name of the file to read from.
FileReader(String fileName)
// Java Program to illustrate reading from
// FileReader using FileReader
public class ReadingFromFile
{
public static void main(String[] args) throws Exception
{
// pass the path to the file as a parameter
FileReader fr =

int i;
}
}
Using Scanner class: A simple text scanner which can parse primitive types and strings using regular expressions.
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.
// using Scanner Class
public class ReadFromFileUsingScanner
{
public static void main(String[] args) throws Exception
{
// pass the path to the file as a parameter
File file =
Scanner sc = new Scanner(file);

}
}
Reading the whole file in a List: Read all lines from a file. This method ensures that the file is closed when all bytes have been read or an I/O error, or other runtime exception, is thrown. Bytes from the file are decoded into characters using the specified charset.
public static List readAllLines(Path path,Charset cs)throws IOException

Possibly if you have doubt comment below and let me understand what else I can help you with information in java.This playlist is a full fledged java programming for beginners and java tutorial for beginners which is given above.
Please share with your friends the video to assist other people looking for java programming tutorial or object oriented programming java .
To never miss an update from or channel hit the subscribe button first and if already subscribe hit the bell icon.
1.Follow us on INSTAGRAM for Interesting posts
2.Follow us on LINKEDIN for interesting content on different aspects
3.Don't forget to like our FACEBOOK to get the most out of it
4.Follow us on twitter to get a mix of all
5.If you want to get us on TUMBLR please then click on the link given below
6.Do join our OFFICIAL Telegram for notes of different things
7.For get job update regularly both private and government do join this telegram channel
#quordnetacademy, #java_tutorial_series, #javatutorialseries
Рекомендации по теме
join shbcf.ru