diff --git a/FileInputOutput/out/production/FileInputOutput/exampleEight.class b/FileInputOutput/out/production/FileInputOutput/exampleEight.class new file mode 100644 index 0000000..61aacea Binary files /dev/null and b/FileInputOutput/out/production/FileInputOutput/exampleEight.class differ diff --git a/FileInputOutput/out/production/FileInputOutput/exampleNine/Main.class b/FileInputOutput/out/production/FileInputOutput/exampleNine/Main.class new file mode 100644 index 0000000..4198561 Binary files /dev/null and b/FileInputOutput/out/production/FileInputOutput/exampleNine/Main.class differ diff --git a/FileInputOutput/out/production/FileInputOutput/exampleSeven/Main.class b/FileInputOutput/out/production/FileInputOutput/exampleSeven/Main.class new file mode 100644 index 0000000..595aff2 Binary files /dev/null and b/FileInputOutput/out/production/FileInputOutput/exampleSeven/Main.class differ diff --git a/FileInputOutput/out/production/FileInputOutput/exampleSix/Main.class b/FileInputOutput/out/production/FileInputOutput/exampleSix/Main.class new file mode 100644 index 0000000..b20906e Binary files /dev/null and b/FileInputOutput/out/production/FileInputOutput/exampleSix/Main.class differ diff --git a/FileInputOutput/src/exampleEight.java b/FileInputOutput/src/exampleEight.java new file mode 100644 index 0000000..9c94bf6 --- /dev/null +++ b/FileInputOutput/src/exampleEight.java @@ -0,0 +1,27 @@ +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import static java.nio.file.StandardOpenOption.*; + +public class exampleEight { + public static void main(String[] args) { + Path file = Paths.get("E:\\javaTest\\Data.txt"); + String s = "DELETE ALL THIS TEXT\n"; + byte[] data = s.getBytes(); + OutputStream output = null; + try { + output = new BufferedOutputStream(Files.newOutputStream(file, CREATE)); + output.write(data); + output.write(data); + output.flush(); + output.close(); + System.out.println("Endring gjennomført"); + + } catch (Exception e) { + System.out.println(e); + } + } +} diff --git a/FileInputOutput/src/exampleNine/Main.java b/FileInputOutput/src/exampleNine/Main.java new file mode 100644 index 0000000..2cec993 --- /dev/null +++ b/FileInputOutput/src/exampleNine/Main.java @@ -0,0 +1,46 @@ +package exampleNine; + +import java.io.BufferedOutputStream; +import java.io.BufferedWriter; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Scanner; +import static java.nio.file.StandardOpenOption.*; + +public class Main { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + Path file = Paths.get("E:\\javaTest\\Data.txt"); + String s = ""; + String delimiter = ", "; + int id; + String name; + double payRate; + final int QUIT = 999; + + try { + OutputStream output = new BufferedOutputStream(Files.newOutputStream(file, CREATE)); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output)); + System.out.println("Enter employee ID number >> "); + id = input.nextInt(); + while(id != QUIT) { + System.out.println("Enter name for employee " + id + " >> "); + input.nextLine(); + name = input.nextLine(); + System.out.println("Enter pay rate >>"); + payRate = input.nextDouble(); + s = id + delimiter + name + delimiter + payRate; + writer.write(s, 0, s.length()); + writer.newLine(); + System.out.println("Enter next ID or QUIT " + QUIT + " to quit"); + id = input.nextInt(); + } + writer.close(); + }catch (Exception e) { + System.out.println(e); + } + } +} diff --git a/FileInputOutput/src/exampleSeven/Main.java b/FileInputOutput/src/exampleSeven/Main.java new file mode 100644 index 0000000..b42f909 --- /dev/null +++ b/FileInputOutput/src/exampleSeven/Main.java @@ -0,0 +1,25 @@ +package exampleSeven; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class Main { + public static void main(String[] args){ + + Path file = Paths.get("E:\\javaTest\\Data.txt"); + String s = ""; + try{ + InputStream input = new BufferedInputStream(Files.newInputStream(file)); + BufferedReader reader = new BufferedReader(new InputStreamReader(input)); + s = reader.readLine(); + while(s != null){ + System.out.println(s); + s = reader.readLine(); + } + } catch (IOException e) { + System.out.println(e.getMessage()); + } + } +} diff --git a/FileInputOutput/src/exampleSix/Main.java b/FileInputOutput/src/exampleSix/Main.java new file mode 100644 index 0000000..fbcd38a --- /dev/null +++ b/FileInputOutput/src/exampleSix/Main.java @@ -0,0 +1,26 @@ +package exampleSix; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class Main { + public static void main (String[] args) { + Path file = Paths.get("C:\\Users\\Sebastian\\Documents\\javaTest\\Data.txt"); + InputStream input = null; + try { + input = Files.newInputStream(file); + BufferedReader reader = new BufferedReader(new InputStreamReader(input)); + String s = null; + s = reader.readLine(); + System.out.println(s); + input.close(); + }catch (IOException e) { + System.out.println(e.getMessage()); + } + } +}