Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. package com.company;
  2. import java.io.*;
  3. import java.net.URL;
  4. import java.util.Scanner;
  5. import java.io.ByteArrayOutputStream;
  6.  
  7. public class Main {
  8.  
  9. public static void main(String[] args)throws IOException, UnsupportedEncodingException {
  10. File F = new File("C:\\Users\\IVC5-8\\IdeaProjects\\untitled\\srcA.txt");
  11. F.createNewFile();
  12. System.out.println(F.getAbsolutePath());
  13. }
  14. public static void MethodOutputStream(InputStream in) throws IOException, UnsupportedEncodingException {
  15. int x;
  16. while ((x = in.read()) != -1) {
  17. System.out.print(" "+ (char) x);
  18. }
  19. System.out.print("\n" + "-------");
  20. }
  21. public static void testInputStream() throws IOException {
  22. try {
  23. byte a[] = new byte[]{48, 49, 50, 51};
  24. InputStream in1 = new ByteArrayInputStream(a);
  25. MethodOutputStream (in1);
  26. OutputStream out1 = new ByteArrayOutputStream();
  27. int x;
  28. in1 = new ByteArrayInputStream(a);
  29. while ((x = in1.read()) != -1) {
  30. out1.write(x*2);
  31. }
  32. out1.toString();
  33. byte c[] = ((ByteArrayOutputStream) out1).toByteArray();
  34. for (byte y:c) {
  35. System.out.print((char)y);
  36. }
  37. in1.close();
  38. out1.flush();
  39. System.out.print("\n");
  40. String tmp = "sjkghnslkghs;klj";
  41. byte b[] = tmp.getBytes();
  42. ByteArrayInputStream in2 = new ByteArrayInputStream(b);
  43. ByteArrayInputStream in3 = new ByteArrayInputStream(b, 0,3);
  44. MethodOutputStream(in2);
  45. System.out.print("\n");
  46. MethodOutputStream(in3);
  47. System.out.print("\n");
  48. in2.close();
  49. in3.close();
  50.  
  51. InputStream inFile = new FileInputStream("C:\\Users\\IVC5-8\\IdeaProjects\\untitled\\srcA.txt");
  52. //InputStream inFile = new FileInputStream(F);
  53. MethodOutputStream(inFile);
  54. } catch (IOException e) {
  55. System.out.print("Ошибка." + e);
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement