Skip to content

Instantly share code, notes, and snippets.

@Cellane
Created April 10, 2010 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cellane/362224 to your computer and use it in GitHub Desktop.
Save Cellane/362224 to your computer and use it in GitHub Desktop.
/**
* Originalni pouziti pretezovani metod
*/
/**
* Zjisti od uzivatele nazev souboru, pak nacte soubor
*
* @return nactene pole
*/
public static int[] nacistPole () {
Scanner sc = new Scanner (System.in);
String nazevSouboru;
System.out.print ("Nazev souboru? ");
nazevSouboru = sc.next ();
return (nacistPole (nazevSouboru));
}
/**
* Nacte pole ze souboru
*
* @param nazevSouboru nazev souboru obsahujici pole
* @return nactene pole
*/
public static int[] nacistPole (String nazevSouboru) {
File ukazatel = new File (MessageFormat.format ("src{0}Pole{1}{2}", File.separator, File.separator, nazevSouboru));
String radek;
String[] poleZnaku;
int[] poleCisel;
try {
FileReader soubor = new FileReader (ukazatel);
BufferedReader ctecka = new BufferedReader (soubor);
radek = ctecka.readLine ();
poleZnaku = radek.split (" ");
poleCisel = new int[poleZnaku.length];
for (int i = 0; i < poleZnaku.length; i++) {
poleCisel[i] = Integer.parseInt (poleZnaku[i]);
}
ctecka.close ();
} catch (FileNotFoundException e) {
poleCisel = new int[0];
System.out.println ("Soubor neexistuje: " + e.getLocalizedMessage () + "!");
} catch (IOException e) {
poleCisel = new int[0];
System.out.println ("Ze souboru nelze cist: " + e.getLocalizedMessage () + "!");
}
return (poleCisel);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment