Created
April 10, 2010 18:54
-
-
Save Cellane/362224 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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