-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
823e8ad
commit c409001
Showing
8 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+2.84 KB
FileInputOutput/out/production/FileInputOutput/exampleNine/Main.class
Binary file not shown.
Binary file added
BIN
+1.49 KB
FileInputOutput/out/production/FileInputOutput/exampleSeven/Main.class
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |