package ITUannotation;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

public class FileReader {
	String FileType;
	File file;
	private String read,read1,outread = null;

	public FileReader(String type, File file)
	{
		FileType=type;
		this.file=file;
		
	}

	private String readTxt(File file2) {
		// TODO Auto-generated method stub
		
		//String read,read1 = null;
		File xmlFile = new File(file2.toURI());
		Scanner scanner = null;
		FileInputStream fis = null;
		BufferedInputStream bis = null;
		DataInputStream dis = null;
		read1 = new String("");

		try {
			fis = new FileInputStream(file2);
			bis = new BufferedInputStream(fis);
			dis = new DataInputStream(bis);
			while (dis.available() != 0) {
				read1 += "\n" + dis.readLine();
			}
			fis.close();
			bis.close();
			dis.close();
			char q = '"';
			String Q = Character.toString(q);
			read1 = read1.replaceAll("&quot;", Q);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{return read1;}
		
		
		
	}

	public String read() {
		if(FileType.contentEquals("txt"))
		{
			outread= readTxt(file);
			//OutputWriter out_wrtr=new OutputWriter(read1,"txt");
		}
		return outread;
		
	}
	
	

}
