Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.net.URL;
- import java.util.Scanner;
- import java.io.ByteArrayOutputStream;
- public class Main {
- public static void main(String[] args)throws IOException, UnsupportedEncodingException {
- File F = new File("C:\\Users\\IVC5-8\\IdeaProjects\\untitled\\srcA.txt");
- F.createNewFile();
- System.out.println(F.getAbsolutePath());
- }
- public static void MethodOutputStream(InputStream in) throws IOException, UnsupportedEncodingException {
- int x;
- while ((x = in.read()) != -1) {
- System.out.print(" "+ (char) x);
- }
- System.out.print("\n" + "-------");
- }
- public static void testInputStream() throws IOException {
- try {
- byte a[] = new byte[]{48, 49, 50, 51};
- InputStream in1 = new ByteArrayInputStream(a);
- MethodOutputStream (in1);
- OutputStream out1 = new ByteArrayOutputStream();
- int x;
- in1 = new ByteArrayInputStream(a);
- while ((x = in1.read()) != -1) {
- out1.write(x*2);
- }
- out1.toString();
- byte c[] = ((ByteArrayOutputStream) out1).toByteArray();
- for (byte y:c) {
- System.out.print((char)y);
- }
- in1.close();
- out1.flush();
- System.out.print("\n");
- String tmp = "sjkghnslkghs;klj";
- byte b[] = tmp.getBytes();
- ByteArrayInputStream in2 = new ByteArrayInputStream(b);
- ByteArrayInputStream in3 = new ByteArrayInputStream(b, 0,3);
- MethodOutputStream(in2);
- System.out.print("\n");
- MethodOutputStream(in3);
- System.out.print("\n");
- in2.close();
- in3.close();
- InputStream inFile = new FileInputStream("C:\\Users\\IVC5-8\\IdeaProjects\\untitled\\srcA.txt");
- //InputStream inFile = new FileInputStream(F);
- MethodOutputStream(inFile);
- } catch (IOException e) {
- System.out.print("Ошибка." + e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement