Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package com.company;
  2. import java.io.*;
  3.  
  4. public class Main {
  5.  
  6. public static void main(String[] args) throws IOException {
  7. String pytania = usingBufferedReader("C:\\PO\\pytania.txt");
  8. pytania = pytania.replace("X","#X");
  9.  
  10. for(int i=0;i<pytania.split("#").length-1;i++){
  11. String a = pytania.split("#")[i];
  12. String path = "c://PO//"+String.valueOf(i)+".txt";
  13. File file = new File(path);
  14. if (file.createNewFile()){
  15. System.out.println("File is created!");
  16. }else{
  17. System.out.println("File already exists.");
  18. }
  19.  
  20. FileOutputStream fileStream = new FileOutputStream(new File(path));
  21. OutputStreamWriter writer = new OutputStreamWriter(fileStream, "Cp1250");
  22. writer.write(a);
  23. writer.flush();
  24.  
  25. }
  26.  
  27. }
  28. private static String usingBufferedReader(String filePath)
  29. {
  30. StringBuilder contentBuilder = new StringBuilder();
  31. try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath),"Cp1250")))
  32. {
  33.  
  34. String sCurrentLine;
  35. while ((sCurrentLine = br.readLine()) != null)
  36. {
  37. contentBuilder.append(sCurrentLine).append("\n");
  38. }
  39. }
  40. catch (IOException e)
  41. {
  42. e.printStackTrace();
  43. }
  44. return contentBuilder.toString();
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement