Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- public class Main {
- public static void main(String[] args) throws IOException {
- String pytania = usingBufferedReader("C:\\PO\\pytania.txt");
- pytania = pytania.replace("X","#X");
- for(int i=0;i<pytania.split("#").length-1;i++){
- String a = pytania.split("#")[i];
- String path = "c://PO//"+String.valueOf(i)+".txt";
- File file = new File(path);
- if (file.createNewFile()){
- System.out.println("File is created!");
- }else{
- System.out.println("File already exists.");
- }
- FileOutputStream fileStream = new FileOutputStream(new File(path));
- OutputStreamWriter writer = new OutputStreamWriter(fileStream, "Cp1250");
- writer.write(a);
- writer.flush();
- }
- }
- private static String usingBufferedReader(String filePath)
- {
- StringBuilder contentBuilder = new StringBuilder();
- try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath),"Cp1250")))
- {
- String sCurrentLine;
- while ((sCurrentLine = br.readLine()) != null)
- {
- contentBuilder.append(sCurrentLine).append("\n");
- }
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- return contentBuilder.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement