package ro.dcsi.internship;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

 public class CsvExporter {
	CsvExporter() {
		System.out.println("instantiated");
	}

	public void export(String inputFilename, String outputFileName) throws IOException {
		String s;
		FileReader fr = null;
		BufferedReader br = null;
		FileWriter fo = null;
		try(fr = new FileReader(inputFilename)) {
			br = new BufferedReader(fr);
			fo = new FileWriter(outputFileName);
			while ((s = br.readLine()) != null) {
				fo.append(s + ",");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		finally{
			try{
				fr.close();
				
				fo.close();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}
		}

	}

	public ArrayList<User> readUsers(String fileName) {
		ArrayList<User> list = new ArrayList<>();
		try (FileReader fr = new FileReader(fileName)) {
			BufferedReader br = new BufferedReader(fr);
			String s;
			String[] splited;
			while ((s = br.readLine()) != null) {
				splited = s.split(",");
				list.add(new User(splited[0], splited[1], splited[2]));
			}
			return list;
		} catch (FileNotFoundException e) {
			throw new RuntimeException(e);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

 }
 



@@ -202,17 +202,16 @@
 yList;%0A%0A
- 
 public c
@@ -384,24 +384,29 @@
 String s;%0A%09%09
+try (
 FileReader f
@@ -414,121 +414,92 @@
  = n
-ull;%0A%09%09BufferedReader br = null;%0A%09%09FileWriter fo = null;%0A%09%09try(fr = new FileReader(in
+ew FileReader(inputFilename); FileWriter fo = new FileWriter(out
 putFile
-n
+N
 ame)
+;
 ) %7B%0A%09%09%09
-br = new 
 Buff
@@ -512,51 +512,35 @@
 ader
-(fr);%0A%09%09%09fo = new FileWriter(outputFileName
+ br = new BufferedReader(fr
 );%0A%09
@@ -643,105 +643,25 @@
 %0A%09%09%09
-e.printStackTrace();%0A%09%09%7D%0A%09%09finally%7B%0A%09%09%09try%7B%0A%09%09%09%09fr.close();%0A%09%09%09%09%0A%09%09%09%09fo.close();%0A%09%09%09%7D%0A%09%09%09catch(IO
+throw new Runtime
 Exce
@@ -669,52 +669,17 @@
 tion
- e)%0A%09%09%09%7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D
+(e);
 %0A%09%09%7D%0A
-%0A
 %09%7D%0A%0A
@@ -1203,11 +1203,6 @@
 %09%7D%0A%0A
- 
 %7D%0A
- %0A%0A%0A

fix compilation error