How to store and load in java using mapping

I am doing my project in java, my project consists of producing a card game.
I my game at the end of each round the computer will ask the player if he/she wants to save the game. I have looked at some methods on how to do this. It seams that I need a type of mapping but how.
I want to take a String (which is entered by the player) and to this String I want to store various peices of data that can be loaded up later.
The data that I want to store are has follows
1. Name of the player - String
2. Name of the computer- String
3. Points of computer sofar- Int
4. Points of player sofar - Int
5. Target points- Int
If there is a better way then please tell me. thankyou

The format of the saved game could be anything. An easy way to do this is by using the MessageFormat class.
Let's say you use the tab character as a delimiter, and you want to write two strings and 3 ints:
MessageFormat mf = new MessageFormat("{0}\t{1}\t{2,number}\t{3,number}\t{4,number}";
Object[] o = new Object[5];
o[0] = playerName;
o[1] = computerName;
o[2] = new Integer(computerPoints);
o[3] = new Integer(playerPoints);
o[4] = new Integer(targetPoints);
String formatted = mf.format(o);
PrintWriter out = new PrintWriter(new FileWriter("save.txt"));
out.println(formatted);
out.close();
// reading:
BufferedReader in = new BufferedReader(new FileReader("save.txt"));
String s = in.readLine();
Object[] values = mf.parse(s);
playerName = (String)values[0];
computerName = (String)values[1];
computerScore = ((Number)values[2]).intValue();
playerScore = ((Number)values[3]).intValue();
targetScore = ((Number)values[4]).intValue();You could also just write each value on its own line and not using MessageFormat, but just read the values line by line and convert String to ints when needed.

Similar Messages

  • How to Store word doc in java using oracle

    hi my name is jagapathi raju i am working in Niit LTD
    can any one tell me how to store A word doc in oracle using java

    Hi Jagapathi
    You can store text/doc files in Database using CLOB/BLOB columns. Let me check if there are any samples...
    Thanks
    Srinivas

  • How to Store word doc in java using oracle9i

    hi
    my name is jagapathi raju i whant a pice of code that will help me to store word doc in oracle9i please do this for me
    bye

    i whant a pice of code that will help me to store word doc in oracle9i please do > this for me Nope, imagine we are consultants who just provide you with a direction to your
    investigation.
    There's a few approachs...
    1. You store the entire word document ( or any arbitrary binary file ) in a BLOB
    field. ( binary large object ).
    Have a search for Oracle, JDBC and BLOB.
    2. You somehow extract the text from the Word document, losing all formating,
    and store the text in a database field. ( CLOB ) Character large object.
    regards,
    Owen

  • How to store and retrieve blob data type in/from oracle database using JSP

    how to store and retrieve blob data type in/from oracle database using JSP and not using servlet
    thanks

    JSP? Why?
    start here: [http://java.sun.com/developer/onlineTraining/JSPIntro/contents.html]

  • HT204053 Why I can't purchase anything from UK Appstore? It says my ID connected to Kazakhstani store and I can't use it here in UK, I used to live in KZ. How to change stores? Create new ID? But I still have my old e-mail address, will it valid?

    Why I can't purchase anything from UK Appstore? It says my ID connected to Kazakhstani store and I can't use it here in UK, I used to live in KZ. How to change stores? Create a new ID? But I still have my old e-mail address, will it valid as a new ID?

    Welcome to the Apple Support Communities
    You can only purchase content on the Kazakhstani store because you created your Apple ID on that country. To change the country, see "Change your iTunes Store country" > http://support.apple.com/kb/HT1311?viewlocale=en_US&locale=en_US

  • How to Store word doc in oracle  using java

    hi
    toall
    can any one tell me how to store word doc in oracle9i using java
    bye

    Please refer to
    http://www.databasejournal.com/features/oracle/article.php/3305771

  • How to compile and register a Java CFX tag with multiple class files?

    All-
    If this is the wrong forum for CFX questions, please let me
    know.
    I need to determine how to compile and register a Java CFX
    tag that contains multiple class files. One class file implements
    the CustomTag interface and the other class files implement various
    supporting classes. All of the documentation that I have found
    talks about using a single class file. I am assuming that a JAR
    file will be involved, but I am not sure of the specifics.
    Thanks in advance for your help.
    -Josh

    Yes, it will involve a jar. Use your java IDE (eclipse,
    etcetera ..) to create a jar containing all of the classes. Check
    your ide's documentation for how to create jar files. After you
    have created the jar, place the jar in the CF class path so CF will
    recognize it. For example the {cf_root}/WEB-INF/lib directory. CF
    must be restarted before it will detect the new jar. After
    restarting CF, register the CFX tag in the ColdFusion Administrator
    using the name of the class that implements the CustomTag
    interface.
    Though it is worth noting you can also instantiate java
    classes directly from ColdFusion (ie without using a CFX
    tag).

  • How to find and install right java for ECC6 intstallation on AIX5.3

    Hello
    I wander how to find and install right java for ECC6 intstallation on AIX5.3. I went thruroughly thru note 723909 and underlying 716927, 1008311 and 1039948 notes but I still do not understand.
    I guess I should logon to IBM site http://www.ibm.com/developerworks/java/jdk/aix/service.html
    where I can choose :
    " Java 1.4.2 64-bit "
    and then :
    "64-bit SDK 1.4.2 base images (at 1.4.2.0 level; in installp format) "->"Base SDK (required)
    Java14_64.sdk.tar  ((50001920)
    then I assume (on AIX ) I should "tar xvf Java14_64.sdk.tar".
    then I get extracted "Java14_64.sdk"
    Is this ok?
    I know on Linux(
    from IBM site I downloaded "IBMJava2-amd64-142.rpm"
    then I issued
    "rpm -i IBMJava2-amd64-142.rpm "
    and finally issued
    "export JAVA_HOME=/opt/IBMJava2-amd64-142")
    What in case of AIX5.3? Could you help me?

    I was told to use smitty (just I am not familiar with it). furdermore i do not hace read.me file. the ziped files are:
    Java14_64.ext
    -rw-rr 1  202 bin    371712 Mar  2  2010 Java14_64.license
    -rw-rr 1  202 bin      3072 Mar  2  2010 Java14_64.msg.ja_JP
    -rw-rr 1  202 bin      3072 Mar  2  2010 Java14_64.msg.Ja_JP
    -rw-rr 1  202 bin      3072 Mar  2  2010 Java14_64.msg.ko_KR
    -rw-rr 1  202 bin      3072 Mar  2  2010 Java14_64.msg.zh_CN
    -rw-rr 1  202 bin      3072 Mar  2  2010 Java14_64.msg.Zh_CN
    -rw-rr 1  202 bin      3072 Mar  2  2010 Java14_64.msg.zh_TW
    -rw-rr 1  202 bin      3072 Mar  2  2010 Java14_64.msg.Zh_TW
    -rw-rr 1  202 bin   4888576 Mar  2  2010 Java14_64.samples
    -rw-r----- 1 root root 67190784 Oct  4 09:53 Java14_64.sdk
    -rw-rr 1 root root 77370639 Nov 20 19:36 Java14_64.sdk.tar.gz
    -rw-r----- 1 root root 12612608 Oct  4 09:53 Java14_64.source

  • How to Starting and Stopping OC4J Server using Ant

    How to Starting and Stopping OC4J Server using Ant
    In the ant task definitions for ant-oracle-classes.jar (see antlib.xml) there are two tasks called
         name="restartServer" classname="oracle.ant.taskdefs.deploy.JSR88StartServer"
         name="shutdownServer" classname="oracle.ant.taskdefs.deploy.JSR88ShutdownServer"
    I thought that these would shutdown and start the OC4J server. I guessed the parameters as – (Does anyone know where 50 ant targets are documented?)
    <oracle:restartServer
    userid="${oc4j.admin.user}"
         password="${oc4j.admin.password}"
         deployeruri="${deployer.uri}"
    />
    <oracle:shutdownServer
         userid="${oc4j.admin.user}"
         password="${oc4j.admin.password}"
         deployeruri="${deployer.uri}"
    />
    This, however does not start and stop the SOA suite. To do that I've hacked this solution together -
    <path id="oc4j.console">
         <pathelement location="${oracle.home}/config"/>
         <pathelement location="${oracle.home}/jlib/startupconsole.jar"/>
         <pathelement location="${oracle.home}/opmn/lib/optic.jar"/>
         <pathelement location="${oracle.home}/lib/xmlparserv2.jar"/>
    </path>
    <target name="stop" description="stop oc4j server" depends="init">
         <java classname="oracle.appserver.startupconsole.view.Runner">
              <classpath refid="oc4j.console"/>
              <sysproperty key="ORACLE_HOME" path="${oracle.home}"/>
              <arg value="stop"/>
         </java>
    </target>
    <target name="start" description="restart oc4j server" depends="init">
         <java classname="oracle.appserver.startupconsole.view.Runner">
              <classpath refid="oc4j.console"/>
              <sysproperty key="ORACLE_HOME" path="${oracle.home}"/>
              <arg value="start"/>
         </java>
    </target>
    This sort of works – except when the SOA suite doesn't stop cleanly – and needs user interaction to press a Close button. This isn't very useful when doing a continous integration build and deploy.
    So, does anyone have any suggestions or alternative methods to do this?
    - frank

    Actually if the server throws exceptions when it stops (which it always has since we applied patch 10.1.3.3) this technique will pause until a user responds to pop-up ... So a better way (I think) is -
    <target name="start" description="start oc4j server" depends="init">
    <java classname="oracle.appserver.startupconsole.view.Runner">
    <classpath refid="oc4j.console"/>
    <sysproperty key="ORACLE_HOME" path="${oracle.home}"/>
    <arg value="start"/>
    </java>
    </target>
    <target name="stop" description="stop oc4j server" depends="init">
    <echo message="We expect OC4J *NOT* to stop cleanly, so we will timeout after 3 minutes ..."/>
    <java classname="oracle.appserver.startupconsole.view.Runner" fork="true" timeout="180000">
    <classpath refid="oc4j.console"/>
    <sysproperty key="ORACLE_HOME" path="${oracle.home}"/>
    <arg value="stop"/>
    </java>
    </target>
    <target name="restart" description="restart oc4j server">
    <antcall target="stop"/>
    <!-- wait for server to quieten down -->
    <waitfor maxwait="2" maxwaitunit="minute">
    <not><http url="http://${oc4j.http.hostname}:${oc4j.http.port}"/></not>
    </waitfor>
    <antcall target="start"/>
    </target>

  • How to compile and run a .java file from another java program

    hello,
    can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?

    Well a smarter way of implementing this is by using a solution provided by Java Itself.
    If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
    http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
    How do i do that ??
    Check out the below articles which would help you of how to do that
    http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
    http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
    http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
    Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
    Hope that might help :)
    REGARDS,
    RaHuL

  • LRv3.2 Networking with an Asst , How to store and retrieve updated work on Win7?

    LRv3.2 Networking with an Asst , How to store and retrieve updated work on Win7 Network?
    We have a working 1gig network in Win7 PRO 64-bit.  and using LRv3.2
    * How do I configure our Files or Cataloges "so"  ALL Edits are veiwable/edit to all?   (we don't work on the Same Shoot/Folder at the same time)
    I NEED to see,  ALL the LR  Edits  (is great with DNG files
    *** BUT,  what I cannot see if I remember correctly (with just the DNG sharing)  is the  CROP or Virtual Copys ... possibly the Brush edits.
    HOW, do I configure to be able to read and edit ...  ALL of the updated/saved  Edits???   (after it is done by my asst.)
    Is creating a New Catalog for EACH  shoot the way to go?   (not sure I like this idea)
    Right now everything is in one(1) catalog  ... and it's getting big ... BUT, this allows us to search , and group ... going way back.
    Would be nice to be able to still do this easily, and with what we have already done.
    With our one BIG Catalog ... not sure if two(2) can access this catalog over the Network at the same time?
    Even though we never Edit the Same Folder or Files at the same time.
    Or will that be a problem over a simple Win7 PRO network?
    Thank you,
    HG

    Aloha Bob,
    Saw your link.  thank you.
    At least I don't feel "alone"  LOL
    At this point ... I am looking for a  "cluncky"   Work Around?
    * I was thinking,  Maybe making a copy of  My Cataloge ...
    Deleting ALL the  Folders in LR  ... except for the one's  that  will be worked by the Asst.
    Then moving that file to the  Asst.  Computer.
    * NEXT,  pointing the  Folder that they are working on ... across the Network to the Servers Files.
    * After they work on it:
    *** IS THERE A WAY ...
    * To  take that Cataloge ... and UPDATE  my Main  Cataloge.
    THIS, is the STEP  ... I don't know how to do.
    Can someone Help me with this?
    Step by Step,  because I am clueless ....
    Talking UPDATE of everything worked on ... including   Virtual copys, and  CROPS.
    Thank you,
    HG

  • How many look and fields in java ?

    How many look and fields in java ?

    lol, theres 4 i believe, that come standard with java. Only problem is, you can't use them all. The Windows one can only be used on windows, the mac on mac. Metal is the default, and theres Motif. So technically, depending on your OS, thers 2 or 3. You can also download Look and Feels, theres tons out there, most want you to pay however. You can also write your own.

  • How the store and retrieval in ServletContext will happen??

    Hello Sir,
    I am developing a chat application thats in Swing & servlets Now I am able to authenticate user and I am using ArrayList to maintain the names of the user globally my storing it in ServletContext
    How to store and retrieve ArrayList from Servletcontext
    And another thing is that we are having personal chat(1-to-1) also. But how to use the thread model is not known to us as we have not faced such a situation before
    So if you could suggest some example code or snippets ot certain links then it would be of great help to us
    Thanks
    Regards
    Monarch

    Hello
    thanks for your reply. Actually we are doing the same thing that u have mentioned in your reply.
    The thing we are trying to do is that when a user is logged in the particular servlet which is responsible for the authentiacation of the user will authenticate the user an then calls method in the Chatter class which is outside the servlet
    The Chatter class declares two mwthods addChatter() and getChatter()
    I am managing the currently logged users in Arraylist using this two mehtods above
    When the first user logs in his entry gets stored at the first position in the arraylist but when other user logs in then his entry overrites the entry of the first user instead of getting stored in the next position.
    The arraylist gets initialized when second user logs in. to overcome this problem i want to store the arraylist into the ServletContext so it will be unique for the whole application and will not get initialized
    So I want to know the process of storing and retrieving the arraylist fro the context
    Hope ull understand me and reply me
    Thanks
    Regards
    Monarch

  • How to start and finish a transaction using EJB 3.0 in JDeveloper

    Hello everybody!
    Does anybody can explain how to start and finish a transaction using EJB 3.0. I need to start a transaction insert some information in some tables and if everything was fine commit the information.
    I put the annotation @TransactionManagement(TransactionManagementType.BEAN) in my session bean and @Resource SessionContext ejbContext; but I don't what anything else I have to do.
    Any help will be appreciate.

    I tryied to use in the client the statement EntityTransaction transaction = myBean.getTransact(); but I receive the EJBException: Cannot use resource level transactions with a container managed EntityManager
    I just need to start a transaction something like this: transaction.begin(); and finish the transaction, something like this: transaction.commit();
    Does anybody can help?

  • How to Create and Deploy Web Services Using Oracle 9i JDeveloper

    Hi,
    My Question is how to create and deploy Web Services using Oracle 9i JDeveloper.Anybody please give me a detailed Reply.Please Reply to [email protected]
    Hopr to Hear From you,
    Regards,
    G Sreekumar

    You could use datasources. You should do this in your BC4J Configuration. Then when deploying your applicaiton use the command -installDataSource (from admin.jar) to create the right datasource.
    You could probably use the name of your connection + "DS" so you can also use it locally in JDeveloper as JDev seesm to create this automaticly for your Connections.

Maybe you are looking for

  • G/L Account for document

    Hi all. I have a question. Is there any posibility of change the G/L Account just for one document (A/P Invoice) in the creation time via SDK? Thanks

  • Trouble creating a MobileMe Gallery with Aperture

    I'm having trouble creating a MobileMe Gallery from within Aperture. In the past it work flawlessly but now it isn't working at all. This is what happens: I create a gallery from within Aperture by clicking on either "New/MobileMe Album, or "New From

  • What is faster Me.Filter or Me.RecordSource

    I created a form that Search As You Type. When you type in a combo box, Access displays matching records. I use the On Change event with a private Sub. To find the records you can use the Form Filter or Form RecordSource property with a Sql Where Cla

  • How to Distribute (in person) MP3 that is linked to Itunes library files - rankings and info

    We have an album on iTunes. When we play shows I want to distribute some data cd's that contain a single mp3 of the title song for promotion. When the recepients load the file into their iTunes - I'd like iTunes to recognize this mp3 as the same file

  • Sysidcfg file for unattended installation with proper IP addressing

    Hi, I've been running jumpstart installation for several Sunfire V210 and V280Rs. I did use the following sysidcfg file but it's complaining regarding NOT finding Jumpstart Directory and subsequently fails to comply with rules file. Though the ./chec