Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Comp;
- import java.io.*;
- import java.util.Scanner;
- /**
- * Created by Stas on 20-Jan-17.
- */
- public class FileManager {
- public void fileInput() {
- try (FileInputStream myFile = new FileInputStream("myFile.txt");) {
- boolean eof = false;
- while (!eof) {
- int byteValue = myFile.read();
- System.out.print(byteValue + " ");
- if (byteValue == -1) {
- eof = true;
- }
- }
- } catch (IOException e) {
- System.out.println("Could not read file: " + e.toString());
- }
- }
- public void fileWrite(){
- FileOutputStream myFile = null;
- Writer out = null;
- try{
- Scanner scannerToFile=new Scanner(System.in);
- String writeToFile=scannerToFile.next();
- myFile = new FileOutputStream("myFile.txt");
- out = new BufferedWriter(new OutputStreamWriter(myFile, "UTF8"));
- out.write(writeToFile);
- } catch (IOException e) {
- System.out.println("Could not write file: " + e.toString());
- } finally {
- if (myFile != null) {
- try {
- out.close();
- myFile.close();
- }
- catch (Exception e1) {
- e1.printStackTrace();
- }
- }
- }
- }
- public void fileCopy(){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement