Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package Comp;
  2.  
  3. import java.io.*;
  4. import java.util.Scanner;
  5.  
  6. /**
  7. * Created by Stas on 20-Jan-17.
  8. */
  9. public class FileManager {
  10. public void fileInput() {
  11. try (FileInputStream myFile = new FileInputStream("myFile.txt");) {
  12.  
  13. boolean eof = false;
  14.  
  15. while (!eof) {
  16. int byteValue = myFile.read();
  17. System.out.print(byteValue + " ");
  18. if (byteValue == -1) {
  19. eof = true;
  20. }
  21. }
  22. } catch (IOException e) {
  23. System.out.println("Could not read file: " + e.toString());
  24. }
  25.  
  26.  
  27. }
  28. public void fileWrite(){
  29. FileOutputStream myFile = null;
  30. Writer out = null;
  31. try{
  32. Scanner scannerToFile=new Scanner(System.in);
  33. String writeToFile=scannerToFile.next();
  34.  
  35. myFile = new FileOutputStream("myFile.txt");
  36.  
  37. out = new BufferedWriter(new OutputStreamWriter(myFile, "UTF8"));
  38.  
  39. out.write(writeToFile);
  40.  
  41. } catch (IOException e) {
  42. System.out.println("Could not write file: " + e.toString());
  43. } finally {
  44. if (myFile != null) {
  45. try {
  46. out.close();
  47. myFile.close();
  48. }
  49. catch (Exception e1) {
  50. e1.printStackTrace();
  51. }
  52. }
  53. }
  54. }
  55.  
  56. public void fileCopy(){
  57.  
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement