import java.io.*;
import java.text.*;
//import java.util.*;

public class SouborIO {
  
  static final int MAX_LENGTH = 100;
  private static String fileInPath="vstup.txt";
  private static String fileOutPath="vystup.txt";

  /*potreba prejmenovat tridu a metody, mozno dodelat osetreni chyb
    metody by mohly obsahovat jmeno souboru jako parametr*/ 
  
  static void setInPath(String path){
    fileInPath = path;
  }

  static void setOutPath(String path){
    fileOutPath = path;
  }
  
  static String formatuj(double cislo, int cela, int desetinna) {
    String vzor = "";
    while (vzor.length() != desetinna) {
      vzor += "0";
    }
    vzor = "#." + vzor;
     
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');
    DecimalFormat df = new DecimalFormat(vzor, dfs);
    String s = df.format(cislo);
    while (s.length() < (cela + desetinna + 1)) {
      s = " " + s;
    }
    return s;
  }
 
  /**
   *Vystup pole celych cisel do souboru
   *
   *V poli musi byt na pozici 0 pocet cisel dale v poli
   */
  public static void vystupInt(int [] data){
    String s;
    /*lze dodelat dalsi metody na jine datove typy*/
    if (data.length<1 ){
      System.err.println("Pole musi mit alespon jeden prvek.");
      return;
    }
    try {
      FileWriter fw = new FileWriter(fileOutPath);
      for (int i=0; i<data[0]; i++){
        if (i<(data.length-1)){
          s = String.valueOf(data[i+1]);
          fw.write(s);
          fw.write("\n");
        }
      } 
      fw.close();   
    } catch (Exception e){
      System.err.println("Chyba pri zapisu do souboru.");
      return;
    }   
  } 

  

  /**
   *Nacteni pole celych cisel ze souboru
   *
   *Delka pole udava pocet cisel v poli
   */
  public static int[] vstupInt(){
   int [] temp = new int[MAX_LENGTH];
   int [] vysledek;
   String radka;
   int pocet=0;

   try{
     FileReader fr = new FileReader(fileInPath);
     BufferedReader in = new BufferedReader(fr);
     while ((radka = in.readLine())!=null){
 //      System.out.println(radka);
       temp[pocet++]= (new Integer(radka)).intValue();
     } 
   
     vysledek = new int[pocet];
   
     for (int i=0; i<pocet; i++)
       vysledek[i]=temp[i];
   
     in.close();
     fr.close();
   }  catch (Exception e){
      System.err.println("Chyba pri cteni ze souboru.");
      vysledek= new int[0];
   }
   return(vysledek);
  } 
  
}
