Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package stream;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.io.Reader;
- import java.io.Writer;
- import java.util.Scanner;
- import java.util.zip.GZIPOutputStream;
- public class Run {
- public void ukol01()throws IOException{
- try(
- InputStream is = new FileInputStream("D:\\workspace\\Faust-Goethe.txt");
- OutputStream os = new FileOutputStream("D:\\workspace\\Faust-Goethe-output.txt");)
- {
- int zn;
- while ((zn = is.read()) != -1){
- os.write(zn);
- }
- }catch (IOException e){
- e.printStackTrace();
- }
- }
- public void ukol02()throws IOException{
- try(
- InputStream is = new FileInputStream("D:\\workspace\\Faust-Goethe.txt");
- OutputStream os = new FileOutputStream("D:\\workspace\\Faust-Goethe-output2.txt");)
- {
- byte[] buffer = new byte[1024*1024];
- int len = 0;
- while (-1 != (len = is.read(buffer,0,buffer.length))){
- os.write(buffer,0,len);
- }
- }catch (IOException e){
- e.printStackTrace();
- }
- }
- public void ukol03()throws IOException{
- try(
- Reader is = new InputStreamReader(new FileInputStream("D:\\workspace\\Faust-Goethe.txt"));
- Writer os = new OutputStreamWriter((new GZIPOutputStream( new FileOutputStream("D:\\workspace\\Faust-Goethe-output3.txt.gz"))),"windows-1250");)
- {
- int zn;
- while (-1 != (zn = is.read())){
- char ch = (char) zn;
- os.write(Character.toUpperCase(ch));
- }
- }catch (IOException e){
- e.printStackTrace();
- }
- }
- public void ukol04(){
- try(
- BufferedReader br = new BufferedReader (new InputStreamReader(new FileInputStream("D:\\workspace\\Faust-Goethe.txt"))))
- {
- String line;
- int count = 0;
- while (null != (line = br.readLine())){
- count++;
- System.out.printf("%d> %s \n",count, line);
- }
- }catch (IOException e){
- e.printStackTrace();
- }
- }
- public void ukol05(){
- try(
- BufferedReader br = new BufferedReader (new InputStreamReader(new FileInputStream("D:\\workspace\\Faust-Goethe.txt"))))
- Scanner sc = new Scanner(br);){
- String word;
- while(sc.hasNextDouble()){
- double d = sc.nextDouble();
- System.out.printf("%d> %s \n",count, line);
- }
- }catch (IOException e){
- e.printStackTrace();
- }
- }
- public static void main(String[] args) throws IOException{
- new Run().ukol04();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement