- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4338 Articles for Java 8
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
242 Views
This writes data into a specific file or, a file descriptor (byte by byte). It is usually used to write the contents of a file with raw bytes, such as images.To write the contents of a file using this class −First of all, you need to instantiate this class by passing a string variable or a File object, representing the path of the file to be read.FileOutputStream outputStream = new FileOutputStream("file_path"); or, File file = new File("file_path"); FileOutputStream outputStream = new FileOutputStream (file);You can also instantiate a FileOutputStream class by passing a FileDescriptor object.FileDescriptor descriptor = new FileDescriptor(); FileOutputStream outputStream ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
730 Views
The BufferedWriter class of Java is used to write a stream of characters to the specified destination (character-output stream). It initially stores all the characters in a buffer and pushes the contents of the buffer to the destination, making the writing of characters, arrays and Strings efficient.You can specify the required size of the buffer at the time of instantiating this class.ExampleIn the following Java program, we are trying to print a line on the console (Standard Output Stream). Here we are invoking the write() method by passing the required String. Live Demoimport java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; public class BufferedWriterExample ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
6K+ Views
The BufferedReader class of Java is used to read the stream of characters from the specified source (character-input stream). The constructor of this class accepts an InputStream object as a parameter.This class provides a method named read() and readLine() which reads and returns the character and next line from the source (respectively) and returns them.Instantiate an InputStreamReader class bypassing your InputStream object as a parameter.Then, create a BufferedReader, bypassing the above obtained InputStreamReader object as a parameter.Now, read data from the current reader as String using the readLine() or read() method.ExampleThe following Java program demonstrates how to read integer data ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
511 Views
While defining a method, In general, we will specify the arguments it accepts along with the type as −myMethod(int a, String b){ }Suppose if you need to accept more than one variable of the same type you need to specify the variables one after the other as −myMethod(int a, int b, int c){ }You can also pass a variable number of arguments of a particular type, to a method. These are known as variable arguments or, varargs. They are represented by three dots (…)Syntaxpublic myMethod(int ... a) { // method body }Once you use variable arguments as a parameter ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
370 Views
In most scenarios, if you try to write content to a file, using the classes of the java.io package, the file will be overwritten i.e. data existing in the file is erased and the new data is added to it.But, in certain scenarios like logging exceptions into a file (without using logger frameworks) you need to append data (message) in the next line of the file.You can do this using the Files class of the java.nio package. This class provides a method named write() which acceptsAn object of the class Path, representing a file.A byte array holding the data to ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
15K+ Views
A library named OpenCSV provides API’s to read and write data from/into a.CSV file. Here it is explained how to write the contents of a .csv file using a Java program.Maven dependency com.opencsv opencsv 4.4 org.apache.commons commons-lang3 3.9 The CSVWriter class of the com.opencsv package represents a simple csv writer. While instantiating this class you need to pass a Writer object representing the file, to which you want to write the data, as a parameter to its constructor.It provides methods named writeAll() and writeNext() to write data to a .csv file.Using the ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
3K+ Views
A library named OpenCSV provides API’s to read and write data from/into a.CSV file. Here it is explained how to read the contents of a .csv file using a Java program.Maven dependency com.opencsv opencsv 4.4 org.apache.commons commons-lang3 3.9 The CSVReader class of the com.opencsv package represents a simple CSV reader. While instantiating this class you need to pass a Reader object representing the file to be read as a parameter to its constructor. It provides methods named readAll() and readNext() to read the contents of a .csv fileUsing the readNext() methodThe readNext() ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
975 Views
The class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.The mkdir() method of this class creates a directory with the path represented by the current object.Therefore, to create a directory −Instantiate the File class by passing the path of the directory you need to create, as a parameter (String).Invoke the mkdir() method using the above-created file object.ExampleThe following Java example reads the path and name of the directory to be created, from the user, and creates it. Live Demoimport java.io.File; import java.util.Scanner; ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
505 Views
Using the File classThe class named File of the java.io package represents a file or directory (pathnames) in the system. This class provides various methods to perform various operations on files/directories.This class provides various methods to manipulate files, The rename() method of the File class accepts a String representing a destination file and, renames the abstract file path of the current file to the given one.This method actually moves the file from the source path to the destination path.Example Live Demoimport java.io.File; public class MovingFile { public static void main(String args[]) { //Creating a source file object ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
11K+ Views
The class named File of the java.io package represents a file or directory (pathnames) in the system. This class provides various methods to perform various operations on files/directories.To get the list of all the existing files in a directory this class provides five different methods to get the details of all files in a particular folder −String[] list()File[] listFiles()String[] list(FilenameFilter filter)File[] listFiles(FilenameFilter filter)File[] listFiles(FileFilter filter)The ListFiles() methodThis method returns an array holding the objects (abstract paths) of all the files (and directories) in the path represented by the current (File) object.The following Java program prints the name, path and, size ... Read More