From cc83dce61303f190526b4332f2e8e1ffdacfe464 Mon Sep 17 00:00:00 2001 From: James Su Date: Thu, 26 Sep 2019 15:40:01 +0000 Subject: [PATCH] Delete Reading And Writing To Files.md --- .../ICS4U1/Reading And Writing To Files.md | 60 ------------------- 1 file changed, 60 deletions(-) delete mode 100644 Grade 10/Computer Science/ICS4U1/Reading And Writing To Files.md diff --git a/Grade 10/Computer Science/ICS4U1/Reading And Writing To Files.md b/Grade 10/Computer Science/ICS4U1/Reading And Writing To Files.md deleted file mode 100644 index 2584715..0000000 --- a/Grade 10/Computer Science/ICS4U1/Reading And Writing To Files.md +++ /dev/null @@ -1,60 +0,0 @@ -## Reading and Outputting Files - -Outputing To Files -- you can save it for future use -- The printwriter class can be used to createa file and wrtie data to it -- necessay imports: -```java -import java.io.IOException; -import java.io.PrintWriter; -``` - -- Or: -``` -import java.io.*; -``` - -- It is declared similarly to the scanner class - -Different types of file can be created for data to be written to, depends on the extension eg. ".txt" creates a text file while docsx creates a docx document - -```java -code - -``` - -## Reading To Files -- Speed -- Less errors -- Easier to read individual cases -- able to get data from sources other than keyboard -- changing information is easy only to file -- more efficient less time to test -- large amounts of data can be entered quickly -- at the testing stage, data can be easily - -## How -- The file class is java's representation of a file or directoy path -- it is used to identify/ocate the file that is to be read -- code -- Scanner calss is used to read from file - -## Sample Code -```java -import java.util.Scanner; -import java.io.File; -import java.io.IOException; -public class ReadingToFileDemo { - public static void (String[]args) throws IOException { - File file = new File("test.txt); // the file you are reading from - Scanner read = new Scanner(file); - while(read.hasNext()) { - System.out.println(read.nextLine()); - read.next(); - } - } -} -``` - - -