Reading and Writing Files in Java

A common task in any programming language is Reading and Writing files. Below are a couple of functions that can be used for these purposes, along with descriptions of their use. Be sure to import java.io for these functions to work.

//Function for Reading Files. You need to pass a string with the path to the file you wish to read. This function will return a string value with the complete contents of the file in question.

 

//Function for Writing files. You need to pass the string you wish to write to a file, along with the path to the file you wish to write to. This function will write the string to the file path you passed to it. This function will over-write any file that is already at that path.