Advertisement
jaVer404

level19.lesson10.bonus02 (done beautifuly)

Mar 30th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. package com.javarush.test.level19.lesson10.bonus02;
  2.  
  3. /* Свой FileWriter
  4. Реализовать логику FileConsoleWriter
  5. Должен наследоваться от FileWriter
  6. При записи данных в файл, должен дублировать эти данные на консоль
  7. */
  8.  
  9. import java.io.File;
  10. import java.io.FileDescriptor;
  11. import java.io.FileWriter;
  12. import java.io.IOException;
  13.  
  14. public class FileConsoleWriter extends FileWriter
  15. {
  16.    
  17.     public FileConsoleWriter(String fileName) throws IOException
  18.     {
  19.         super(fileName);
  20.     }
  21.  
  22.     public FileConsoleWriter(String fileName, boolean append) throws IOException
  23.     {
  24.         super(fileName, append);
  25.     }
  26.  
  27.     public FileConsoleWriter(File file) throws IOException
  28.     {
  29.         super(file);
  30.     }
  31.  
  32.     public FileConsoleWriter(File file, boolean append) throws IOException
  33.     {
  34.         super(file, append);
  35.     }
  36.  
  37.     public FileConsoleWriter(FileDescriptor fd)
  38.     {
  39.         super(fd);
  40.     }
  41. /*----------------------------------------------------------*/
  42.  /*1*/
  43.     public void write(int c) throws IOException {
  44.         System.out.print(Character.toString ((char) c));
  45.         super.write(c);
  46. }
  47.  /*2*/
  48.     public void write(char cbuf[], int off, int len) throws IOException {
  49.         System.out.print(new String(cbuf,off,len));
  50.         super.write(cbuf, off, len);
  51.     }
  52.  
  53. /*3*/
  54.     public void write(String str, int off, int len) throws IOException {
  55.         System.out.print(str.substring(off,len));
  56.         super.write(str, off, len);
  57.     }
  58. /*---------------------------------------------------------*/
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement