Skip to content
Snippets Groups Projects
Commit 9c4166a8 authored by Läspä Vili Valtteri's avatar Läspä Vili Valtteri
Browse files

liikeiden tallentaminen tiedostoon alku

parent 9ce0af1c
Branches main
No related tags found
No related merge requests found
No preview for this file type
1|Kyykky3|leveä|2|Syvä|Tanko
2|Kyykky12|neutraali|9|Syvä|Tanko
......@@ -113,6 +113,26 @@ public class Liike {
}
/**
* palauttaa liikkeen tiedot merkkijonona jonka voi tallentaa tiedostoon.
* @return liike tolppaeroteltuna merkkijonona
* @example
* <pre name="test">
* Liike liike = new Liike();
* liike.parse("7 | kyykky | leveä");
* liike.toString.startsWith("7|kyykky|leveä") === true;
*/
@Override
public String toString() {
return "" +
getLid() + "|" +
liike + "|" +
oteLeveys + "|" +
stoppi + "|" +
syvyys + "|" +
suoritusValine;
}
/**
* @param args ei käytössä
......
package puntti;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
/**
*
* |------------------------------------------------------------------------|
......@@ -86,6 +91,24 @@ public class Liikkeet {
return lkm;
}
/**
* @param hakemisto mihin hakemistoon tehdään uusi tiedosto
* @throws SailoException jos tallentaminen ei onnistu
*/
public void tallenna(String hakemisto) throws SailoException {
File tiedosto = new File(hakemisto + "/liikkeet.dat");
try (PrintStream fo = new PrintStream(new FileOutputStream(tiedosto, false))){
for (int i=0; i<this.getLkm();i++) {
Liike liike = this.anna(i);
fo.println(liike.toString());
}
}catch (FileNotFoundException e) {
throw new SailoException("Tiedosto "+ tiedosto.getAbsolutePath() + " ei löydy");
}
}
/**
* @param args ei käytössä
......@@ -118,6 +141,11 @@ public class Liikkeet {
System.out.println(ex.getMessage());
}
try {
liikkeet.tallenna("batman");
} catch (SailoException e) {
System.err.println(e.getMessage());
}
......
......@@ -123,6 +123,15 @@ public class Puntti {
}
/**
* tallentaa kerhon tiedot tiedostoon
* @param nimi käyttäjän hakemiston nimi
* @throws SailoException jos tallennus ei onnistu
*/
public void tallenna(String nimi) throws SailoException {
liikkeet.tallenna(nimi);
}
/**
* Testiohjelma Puntti.javalle
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment