[ Java Programming ] Reading and Writing text files tutorial

Pubblicato il: 04 aprile 2018
sul canale di: 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();

}
}


In questa pagina del sito puoi guardare il video online [ Java Programming ] Reading and Writing text files tutorial della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Code Splosion 04 aprile 2018, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 117 volte e gli è piaciuto 1 spettatori. Buona visione!