Sanady

Untitled

Mar 3rd, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package zadania1;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.FileInputStream;
  10. import java.io.FileOutputStream;
  11. import java.io.IOException;
  12. import java.io.InputStreamReader;
  13. import java.io.OutputStreamWriter;
  14. import java.io.PrintWriter;
  15.  
  16. public class Zadania1
  17. {
  18.     public static void main(String[] args)
  19.     {
  20.         String TextFromFile = "";
  21.         Zadania1 zad = new Zadania1();
  22.         TextFromFile = zad.NacitajObsahZoSubora("C:\\Users\\Ivan\\Desktop\\test.txt");
  23.         String[] pole = TextFromFile.split("(?<=\\])");
  24.         System.out.println("Frist matrica: " + pole[0] +" Second matrica: " + pole[1] +"");
  25.         String[] matrica1 = pole[0].split("(?<=\\;)");
  26.         System.out.println("First Matrica: "+ matrica1[0] +"\n " + matrica1[1] +"");
  27.         String[] matrica2 = pole[1].split("(?<=\\;)");
  28.         System.out.println("Second Matrica:\n "+ matrica2[0] +"\n " + matrica2[1] +"\n "+ matrica2[2] +"");
  29.     }
  30.    
  31.     public String NacitajObsahZoSubora(String fileName)
  32.     {
  33.         String text = "", tmp;
  34.         try
  35.         {
  36.             FileInputStream file = new FileInputStream(fileName);
  37.             InputStreamReader input = new InputStreamReader(file);
  38.             try (BufferedReader fromFile = new BufferedReader(input))
  39.             {
  40.                 while((tmp = fromFile.readLine()) != null)
  41.                 {
  42.                     text = text + "\n" + tmp;
  43.                 }
  44.                 System.out.println("Obsah suboru:\n" + text);
  45.             }
  46.         }
  47.         catch(IOException e)
  48.         {            
  49.         }
  50.         return text;
  51.     }
  52.    
  53.     public void ZapisObsahDoSubora(String fileName, String writeText)
  54.     {
  55.         try
  56.         {
  57.             FileOutputStream file = new FileOutputStream(fileName);
  58.             OutputStreamWriter output = new OutputStreamWriter(file);
  59.             try (PrintWriter toFile = new PrintWriter(output))
  60.             {
  61.                 toFile.println("" + writeText);
  62.             }
  63.         }
  64.         catch (IOException e)
  65.         {  
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment