Skip to content

Commit

Permalink
h
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-gott committed Mar 16, 2021
1 parent 823e8ad commit c409001
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions FileInputOutput/src/exampleEight.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
46 changes: 46 additions & 0 deletions FileInputOutput/src/exampleNine/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
25 changes: 25 additions & 0 deletions FileInputOutput/src/exampleSeven/Main.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
26 changes: 26 additions & 0 deletions FileInputOutput/src/exampleSix/Main.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
}

0 comments on commit c409001

Please sign in to comment.