[ Java Programming ] Reading and Writing text files tutorial

Veröffentlicht am: 04 April 2018
auf dem Kanal: Code Splosion
117
1

I hope you were able to make use of this video. Included below is the source code that was utilized in this project.

package javaio;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
/**

@author Code Splosion :)
*
*/
public class FileInputOutput {
public static void main(String[] args) {
String stringOfInfo = "Hello World. Today's date is 04 April, 2018";
String result = "";
try {
System.out.println("Writing to file");
writeFile(stringOfInfo, "textinfo.txt");
System.out.println();
result = readData("textinfo.txt");

} catch (FileNotFoundException exceptio) {
exceptio.printStackTrace();
}

System.out.println();
System.out.println(result);
}

private static String readData(String fileName) throws FileNotFoundException {
File fileObj = new File(fileName);
Scanner scanner = new Scanner(fileObj);
String result = "";

while(scanner.hasNextLine()) {
result += scanner.nextLine();
}

scanner.close();

return result;
}

private static void writeFile(String stringOfInfo, String fileName) throws FileNotFoundException {
File fileObj = new File(fileName);
PrintWriter pw = new PrintWriter(fileObj);

pw.println(stringOfInfo);

pw.close();

}
}


Auf dieser Seite können Sie das Online-Video [ Java Programming ] Reading and Writing text files tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Code Splosion 04 April 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 117 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!