Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. package stream;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.BufferedOutputStream;
  5. import java.io.BufferedReader;
  6. import java.io.FileInputStream;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.InputStreamReader;
  11. import java.io.OutputStream;
  12. import java.io.OutputStreamWriter;
  13. import java.io.Reader;
  14. import java.io.Writer;
  15. import java.util.Scanner;
  16. import java.util.zip.GZIPOutputStream;
  17.  
  18. public class Run {
  19.  
  20. public void ukol01()throws IOException{
  21.  
  22.  
  23. try(
  24. InputStream is = new FileInputStream("D:\\workspace\\Faust-Goethe.txt");
  25. OutputStream os = new FileOutputStream("D:\\workspace\\Faust-Goethe-output.txt");)
  26. {
  27. int zn;
  28. while ((zn = is.read()) != -1){
  29.  
  30. os.write(zn);
  31. }
  32. }catch (IOException e){
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. public void ukol02()throws IOException{
  38.  
  39.  
  40. try(
  41. InputStream is = new FileInputStream("D:\\workspace\\Faust-Goethe.txt");
  42. OutputStream os = new FileOutputStream("D:\\workspace\\Faust-Goethe-output2.txt");)
  43. {
  44. byte[] buffer = new byte[1024*1024];
  45. int len = 0;
  46. while (-1 != (len = is.read(buffer,0,buffer.length))){
  47.  
  48. os.write(buffer,0,len);
  49. }
  50. }catch (IOException e){
  51. e.printStackTrace();
  52. }
  53. }
  54.  
  55.  
  56. public void ukol03()throws IOException{
  57.  
  58.  
  59. try(
  60. Reader is = new InputStreamReader(new FileInputStream("D:\\workspace\\Faust-Goethe.txt"));
  61. Writer os = new OutputStreamWriter((new GZIPOutputStream( new FileOutputStream("D:\\workspace\\Faust-Goethe-output3.txt.gz"))),"windows-1250");)
  62. {
  63. int zn;
  64. while (-1 != (zn = is.read())){
  65.  
  66. char ch = (char) zn;
  67. os.write(Character.toUpperCase(ch));
  68. }
  69. }catch (IOException e){
  70. e.printStackTrace();
  71. }
  72. }
  73.  
  74. public void ukol04(){
  75.  
  76.  
  77. try(
  78. BufferedReader br = new BufferedReader (new InputStreamReader(new FileInputStream("D:\\workspace\\Faust-Goethe.txt"))))
  79. {
  80. String line;
  81. int count = 0;
  82. while (null != (line = br.readLine())){
  83. count++;
  84. System.out.printf("%d> %s \n",count, line);
  85. }
  86. }catch (IOException e){
  87. e.printStackTrace();
  88. }
  89. }
  90. public void ukol05(){
  91.  
  92.  
  93. try(
  94. BufferedReader br = new BufferedReader (new InputStreamReader(new FileInputStream("D:\\workspace\\Faust-Goethe.txt"))))
  95. Scanner sc = new Scanner(br);){
  96.  
  97. String word;
  98.  
  99. while(sc.hasNextDouble()){
  100. double d = sc.nextDouble();
  101. System.out.printf("%d> %s \n",count, line);
  102. }
  103. }catch (IOException e){
  104. e.printStackTrace();
  105. }
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. public static void main(String[] args) throws IOException{
  114.  
  115. new Run().ukol04();
  116.  
  117.  
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement