Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cwiczymy;
- import java.io.*;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Cwiczymy {
- public static void main(String[] args) throws IOException
- {
- String sciezkaWej = "dane.txt";
- String sciezkaWyj = "dane - kopia.txt ";
- Stworz(sciezkaWej);
- Przepisz(sciezkaWej, sciezkaWyj);
- Licz(sciezkaWej);
- }
- public static void Stworz(String sciezka)
- {
- try
- {
- BufferedWriter bW = new BufferedWriter(new FileWriter(sciezka));
- bW.write("Ala ma kota");
- bW.newLine();
- bW.write("kot ma Ale");
- bW.newLine();
- bW.write("Virtus.pro gra jak gówno");
- bW.newLine();
- bW.write("To jest taniec to jest życie");
- bW.newLine();
- bW.write("Lubie placki");
- bW.close();
- }
- catch (IOException ex)
- {
- System.out.println(ex.getMessage());
- }
- }
- public static void Przepisz(String sciezkaWejscia,String sciezkaWyjscia)
- {
- try
- {
- BufferedReader bR = new BufferedReader(new FileReader(sciezkaWejscia));
- BufferedWriter bW = new BufferedWriter(new FileWriter(sciezkaWyjscia));
- String linijka = "";
- while ((linijka = bR.readLine()) != null)
- {
- bW.write(linijka);
- bW.newLine();
- bR.readLine();
- }
- bW.close();
- bR.close();
- }
- catch (FileNotFoundException ex)
- {
- System.out.println(ex.getMessage());
- }
- catch (IOException ex)
- {
- System.out.println(ex.getMessage());
- }
- }
- public static int[] Licz(String sciezka) throws IOException
- {
- Scanner plikWe = null;
- int iloscWyrazow = 0;
- int iloscCharow = 0;
- int iloscBialychZnakow = 0;
- int [] tabZwrotna = new int [3];
- try
- {
- plikWe = new Scanner(new BufferedReader(new FileReader(sciezka)));
- BufferedWriter dopisz = new BufferedWriter(new FileWriter(sciezka, true));
- FileReader plikWe_1 = new FileReader(sciezka);
- // liczenie wyrazów w tekście
- while (plikWe.hasNext())
- {
- plikWe.next();
- iloscWyrazow++;
- }
- // liczenie charów w tekscie
- int c = 0;
- while ((c = plikWe_1.read()) != -1)
- {
- if (Character.isWhitespace((char)(c)) != true)
- {
- iloscCharow++;
- }
- else if (Character.isWhitespace((char)(c)))
- {
- iloscBialychZnakow++;
- }
- }
- dopisz.newLine();
- dopisz.newLine();
- dopisz.append("Ilość wyrazów to: " + iloscWyrazow);
- dopisz.newLine();
- dopisz.append("Ilość charów to: " + iloscCharow);
- dopisz.newLine();
- dopisz.append("Ilość bialych znakow: " + iloscBialychZnakow);
- dopisz.close();
- plikWe.close();
- }
- catch (FileNotFoundException ex)
- {
- System.out.println(ex.getMessage());
- }
- tabZwrotna[0] = iloscWyrazow;
- tabZwrotna[1] = iloscCharow;
- tabZwrotna[2] = iloscBialychZnakow;
- return tabZwrotna;
- }
- public static void szukaj(String sciezkaWej, String sciezkaWyj, String wyraz)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement