Need example of properties file use

I'm writing a text based adventure game to get some practice with the Java language. The only thing that's proving to be difficult is saving the game. I need an example of a class for basic properties operations. I've found various tutorials that all have some helpful information, but putting it all together isn't working for me. Here is what I have.
import java.io.BufferedWriter;
import java.io.FileWriter;
public class SaveGame{
public static void CreateSave(String name){//create the save file
    try{
        FileWriter fstream = new FileWriter(name+".properties");
        BufferedWriter out = new BufferedWriter(fstream);
        out.write("*-=Character Information=-*");
        out.write("name= \ngender= \n");
        out.write("*-=Basic Stats=-*");
        out.write("str= \nagl= \nend= \nchr= \nitl= \nlck= \n");
        out.close();
        }catch(Exception e){System.err.println("Error: " + e.getMessage());}
}//CreateSave
public static void SaveStatus/*save all variables to the file*/
(double str, double agl, double end, double chr, double itl,
  double lck, String name, char gender){
// I don't know how to edit values
}//SaveStatus
public static void ReadSave(){//reads the file and sends the variable back to main class
}//ReadSave
}//class The big thing is, I don't know how to edit the values in the properties file. I can handle reading them but i don't know how to convert the string values to int, double, etc. Thanks in advance.

Dillon_91 wrote:
Thanks for those.
Can you link to a decent tutorial on the properties class? Most of what I've found is a little more technical than I'm ready for, and they don't have examples.Suns own Java tutorial has some code snippets, that should get you going - [Properties tutorial|http://java.sun.com/docs/books/tutorial/essential/environment/properties.html]

Similar Messages

  • Get the pc name with domain name and add it to my properties file using commands

    i want to get the pc name with domain name and add it to my properties file using powershell  .
    sid

    function Get-Environment{
    [environment]|Get-Member -Static -MemberType Properties |
    ForEach-Object{
    if($_.Name -ne 'StackTrace'){
    $v=[scriptblock]::Create("[environment]::$($_.Name)").Invoke()
    New-Object PsCustomObject -Property ([ordered]@{Name=$_.Name;Value=$v[0]})
    Get-Environment
    Get-Environment | Out-String | Out-File environment.txt
    ¯\_(ツ)_/¯

  • I need to export Quicktime files using the PhotoJPEG, MJPEG-A, or DV codec.  Is this possible in Final Cut Pro X?  In the options under export I don't see any of these available.

    I need to export Quicktime files using the PhotoJPEG, MJPEG-A, or DV codec.  Is this possible in Final Cut Pro X?  In the options under export I don't see any of these available.  I'm a newbie to this so any help would be greatly appreciated.

    I'm importing .MOV files from my Canon 5Dmk2 at 1080p.  So should I just export using a different codec and then use Compressor or MPEG Streamclip to convert to an MJPEG-A or PhotoJPEG codec?

  • How we write into properties file using get class method

    Hi
    I want to set some value into properties file using given code
    can any one please tell me how i can do this.
    property file
    setting.properties
    Name     =     abc
    and code I use is
    java.io.InputStream oInputStream = this.getClass().getResourceAsStream("Setting.properties");
                   Properties obj = new Properties();
                   obj.load(oInputStream);
                   String myName = obj.getProperty("Name");
                   System.out.println("myName :"+myName);
                   obj.setProperty("Name","def");
                   FileOutputStream oOutput= new FileOutputStream("Setting.properties");
                   obj.store(oOutput, "");
    thanks.

    You can't.
    If you have properties that change dynamically, you should not be using a properties file that sits in the classpath, you should be using Preferences, or a properties file that sits in some application or possibly even user directory, but not one in the classpath. The proper way to do this, would be to have a properties file in your jar (or otherwise in your classpath) that contains the defaults, and another one outside of the classpath in one of the twwo above mentioned areas, then, you read the default one only if the other doesn't exist, or you read the default one first, then read the other overwriting the values from the defaults.
    Don't forget to save the properties again (right after loading if you loaded, or always load, the defaults) after every change.

  • Need example to create File names dynamically using File adapter

    hello,
    I am mapping an IDOC to a flat file using XI and a file adapter. I need to be able to output a file name dynamically depending on the data in the IDOC.  For example if the IDOC has 310 as the company code, the file name should be xyz.310 and if the IDOC has 600 as the company code, the file name created by the file adapter should be xyz.600.  Please some body provide me with an example of the XSLT code that I will have to write in the dispatcher User Exit.
    Any help will be greatly appreciated.

    Nope
    But you could add a dummy row to your source to include column headers and then use options column headers in first row in flat file connection manager.
    So suppose you've three columns column0,coulmn1,column2 and you want to make it as ID,Name,Datethen make source query as
    SELECT 'ID' AS Col1,'Name' AS Col2,'Date' AS Col3, 0 AS ord
    UNION ALL
    SELECT Column1,Column2,Column3,1
    FROM YourTable
    ORDER BY Ord
    then choose  column headers in first row option
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • I need help renaming a file using regular expressions in Bridge.

    Hi,
    I work at a university, and we are working through files for our Thesis and Dissertations. We have been renaming them to make them more consistent. I am just wondering if there is a regular expression that could help with this process?
    Here is come examples of current file names;
    THESIS 1981 H343G
    Thesis 1981 g996e
    THESIS-1981-A543G
    I don't need to change the actual names of the files. just how they are formatted.
    Proper case on Thesis.
    Hyphens(-) in all white space.
    First letter capital, last letter lowercase on the call no (H343g)
    So the list above should look like;
    Thesis-1981-H343g
    Thesis-1981-G996e
    Thesis-1981-A543g
    I have seen people do some pretty cool things with regular expressions! Any help would be greatly appreciated. Thanks!

    You would be better off using a script to do this as an example as I don't think it would be possible in the Bridge re-name.
    Using ExtendScript Toolkit or a Plain text editor copy the code into either and save it out as Filename.jsx
    This needs to be saved into the correct folder. this is found by going to the preferences in Bridge, selecting Startup Scripts, this will open the folder where the script is to be saved.
    Once this is done close and re-start Bridge.
    To Use: Goto the Tools Menu and select Rename PDFs
    Make sure you test the code with a few copied files into a seperate folder first to make sure it does what you want.
    The script will do all PDF files in the selected folder.
    #target bridge 
    if( BridgeTalk.appName == "bridge" ) { 
    renamePDFs = MenuElement.create("command", "Rename PDFs", "at the end of Tools");
    renamePDFs.onSelect = function () {
    app.document.deselectAll();
    var thumbs = app.document.getSelection("pdf");
    for( var z in thumbs){
    var Name = decodeURI(thumbs[z].spec.name);
    var parts = Name.toLowerCase().replace(/\s/g,'-').match(/(.*)(-)(.*)(-)(.*)(\.pdf)/);
    var NewName = parts[1].replace(/^[a-z]/, function(s){ return s.toUpperCase() });
    NewName += parts[2]+parts[3]+parts[4]+parts[5].toUpperCase().replace(/[A-Z]$/, function(s){ return s.toLowerCase() });
    NewName += parts[6];
    thumbs[z].spec.rename(NewName);

  • HOw to access ApplicationResource.properties file using getSystemResource

    I am using struts. I need to access ApplicationResource.properties file, which I define my connection String there. All my methods are static method, so I cannot use getResourceAsStream() method from ClassLoader class, so i have to use getSystemResourceAsStream() method. However, I always get class not found error. Inputstream is always null.
    my ApplicationResource.properties file is stored in projectname/classes, and all my other classes store in projectname/classes/com/testname/. Can anybody tell me how to make it work? Thank you in advance.
    Here is my code:
    private static String getConnectionURL() throws FileNotFoundException,IOException,ClassNotFoundException
    Properties properties = new Properties();
    InputStream fromFile = ClassLoader.getSystemResourceAsStream("ApplicationResources.properties");
    if (fromFile !=null)
    properties.load(fromFile);
    String connectionURL = properties.getProperty("progressiveURL");
    return connectionURL;
    }

    Try either:
    ClassLoader.getSystemResourceAsStream("/ApplicationResources.properties");
    or
    YourClass.class.getResourceAsStream("/ApplicationResources.properties");
    in either case, you need to add the "/" prefix.

  • SQL08 Need example of creating AND using a Fact (degenerate) dimension

    Can someone post a link to some examples of setting up and using a Fact (degenerate) dimension.  Ive got the SSAS 2008R2 Adventureworks DW project setup and I see a few Fact dimensions in there, but id like some descriptions to go along with this or
    something similar.
    My scenario:
    Orders - attributes include :  Order#, OrderStartDate, SalesPerson, BusinessType, MarketType
    OrderTransactions - attributes include:  OrderKey , TransactionAmount, TransactionType, TransactionDate, AccountKey
    Description:
    Its more or less the typical Order > Order Detail type scenario, with the addition of Orders have some additional attributes.
    So I want to be able to measure on for example:
    Order counts - broken down by BusinessType and MarketType , and then within a date range
    Revenue - which will be totals of transaction amounts, again grouped by BusinessType and MarketType, but also be able to drill down to see the related Order#

    Hi Shiftbit,
    According to your description, you need some examples about create and use degenerate dimensions, right?
    Degenerate dimensions, also called fact dimensions, are standard dimensions that are constructed from attribute columns in fact tables instead of from attribute columns in dimension tables. Here is document that describes how to create and use degenerate
    dimensions step by step, please refer to the links below.
    https://msdn.microsoft.com/en-us/library/ms167409(v=sql.100).aspx
    http://www.jamesserra.com/archive/2011/11/degenerate-dimensions/
    Regards,
    Charlie Liao
    TechNet Community Support

  • Approach needed for processing huge file.using file-jdbc

    Hi,
    My Scenario is file-jdbc. I need to update the records in database table. The size of file would be 500mb.
    1)Will the recordsets per message in the sender side FCC will help me in processing the file? Any other better solution or any configuration needs to be checked on PI system? as processing should be finished in 3 hours time?
    2)i need to update other table with no.of records processed per cycle with time. How to acheive this?
    TIA

    I would suggest you to go for Stored procedures and follow as mentioned below:
    1)Use recordsets per message in the sender side FCC (already mentioned by u)
    2) Create a SP and and pass source payload as xml input to the SP.
    Ur target structure will be something like this:
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm
    <StatementName>
    <storedProcedureName action=u201D EXECUTEu201D>
    <table>realStoredProcedureeName</table>
    <param1 type=SQLDatatype>val1</param1>
    </storedProcedureName >
    </StatementName>
    pass ur source data as xml input to param1.
    If u r using PI7.1 then chk this:
    http://www.sappi.sapag.co.in/flat-file-to-file-senario/convert-the-input-xml-to-string-in-pi-7-1-using-standard-graphical-mapping-2/
    on the database side parse the string (xml document) and then insert the data in the table.. Chk with ur DB team regarding the same.

  • How to use JDBC Appender of log4j using a properties file

    Hi,
    I am trying to implement the Log4j JDBC Appender to log the messages to Database(oracle).Can anyone provide me with a sample code along with the properties file used.
    need urgent help.
    Thanks in advance

    Actually, I konw where my problem in my code is. Use functions  
    PDDocAcquirePage(), PDPageGetAnnot(),
    PDTextAnnotGetContents(),
    PDTextAnnotGetContents()
    step by step with the logic designed by ourself can finish my task.
    But also thanks for your help!
     

  • Use resourceBundle properties file from KM

    Hi,
    I have a properties file called com.mycomp.apps.phonebook.properties in the KM Content of the portal in KM Content => root => mycomp => apps => phonebook => customizing
    Now I'm developing a new LinkCommand service for the UserDetails.
    http://help.sap.com/saphelp_nw04/helpdata/en/65/29b24053c13f5fe10000000a155106/frameset.htm
    The already existing LinkCommand "Send E-mail..." is read from the original resourceBundle com.sap.ip.collaboration.gwui.api.wdf.mail.SendTo
    For my new LinkCommand I would like to use the existing properties file. How do I have to define this file in the uicommand xml or properties xml sheet?
    Can anybody help me?
    With the local project resourceBundle it's working, but I would like to use the file in the KM. Andy ideas?
    Regards,
    Stefan

    Hi Praven,
    Copying all existing SendTo properties file to my project would be an option but I wouldn't win anything.
    I'm quite happy with the existing SAP collaboraton properties files using e.g. for "Send e-mail".
    I won't change this existing ones. I created a new LinkCommand. And for this new LinkCommand I'm looking for a solution how I can handle the translation for it.
    I would prefer e using my existing file which is located in the KM. The reason why it's located in the KM is, if I need to change a translation or add a new translation properties file I only need to change it in the KM. If it's a part of the project I need by every change to deploy the project new.

  • PLEASE HELP. How do you access properties files in WEB-INF  and classes directory

    We have a war file that needs to access properties files that are in the WEB-INF directory
    of the war file. We also need to load one of the properties files from the classpath.
    However, when we deploy the application ( an ear which inlcludes an ejbjar and a
    war and the libraries both the ejbjar (with a manifest setting the classpath ) and
    war need ) the properties don't get extracted.
    In some of our servlets we are trying to access those files with the path "WEB-INF/foo.properties"
    and we get a FileNotFoundException. Then we check and see that NO properties files
    have been extracted into their appropriate places ( not even those we throw into
    the WEB-INF/classes directory ).
    PLEASE HELP,
    Christian Hargraves

    The file doesn't have to be extracted from the war. For example, you can place
    test.properties into your app WEB-INF and write a simple JSP to see how it
    works:
    <%
    InputStream in = application.getResourceAsStream("/WEB-INF/test.properties");
    %>
    It will return you a zip inputstream if you deployed your application as a .war.
    Christian Hargraves <[email protected]> wrote:
    I try this, but I get a NullPointerException. The file never actually gets extracted
    from the war. Under tomcat and resin this works great ( that's why I am having all
    of the trouble i am having ), but there are absolutely no properties files in the
    extracted directories for WebLogic deploys. only:
    WEB-INF/some_tmp_dir/WEB-INF/lib
    and then some dynamically generated jor file with all of the classes that would normally
    go in WEB-INF/classes ( all except the properties, of course, which are no where
    to be found. ).
    There has to be some kind of setting I am missing. Please don't make me seperate
    these properties files from the war/ear and then put the path to these properties
    files in the CLASSPATH, changing one step to three steps to deploy!!
    I have found a documented bug where you can't even put the properties files in a
    jar file and that bug will never be fixed for WebLogic 6.1.
    "Dimitri I. Rakitine" <[email protected]> wrote:
    To access files in WEB-INF you can use ServletContext.getResourceXXX("/WEB-INF/filename")
    Christian Hargraves <[email protected]> wrote:
    We have a war file that needs to access properties files that are in theWEB-INF directory
    of the war file. We also need to load one of the properties files fromthe classpath.
    However, when we deploy the application ( an ear which inlcludes an ejbjarand a
    war and the libraries both the ejbjar (with a manifest setting the classpath) and
    war need ) the properties don't get extracted.
    In some of our servlets we are trying to access those files with the path"WEB-INF/foo.properties"
    and we get a FileNotFoundException. Then we check and see that NO propertiesfiles
    have been extracted into their appropriate places ( not even those wethrow into
    the WEB-INF/classes directory ).
    PLEASE HELP,
    Christian Hargraves--
    Dimitri
    Dimitri

  • Execute java code taken from a properties file

    I have a requirement to store some java code in the Properties file & use the code inside the program later. Is there a way I can execute this code after I get it from the .properties file which is retrieved using the ResourceBundle?
    Example:
    File: system.properties
    Item_list=blocksBean.menu(QueryValue,request.getContextPath())
    Inside my Java program I'm using this..
    theBody=codesBean.replaceAll(theBody, "%%menu%%",ResourceBundle.getBundle("system").getString("Item_list"), true);
    instead of
    theBody=codesBean.replaceAll(theBody, "%%menu%%",blocksBean.menu(QueryValue,request.getContextPath()), true);
    This doesn't work because ResourceBundle.getBundle("... returns the value.. which is a string "blocksBean.menu(QueryValue,request.getContextPath())". But what I need is it has to be executed..
    blocksBean.menu() returns a string value of html code fetched from the dartabase.
    Is there a way I can execute blocksBean.menu() which is retrieved from the .properties file.. If anyone has done it / have an idea on this.. please e-mail me [email protected]
    I need something like an eval() in javaScript..
    Thanks in advance
    -ashok

    These boys might have something that will help you:
    http://www.beanshell.org/
    Good luck
    Lee

  • Connection to iFS from a remote station & .properties file syntax

    Hello,
    I want to make a java application (running on a simple NT workstation) that is able to connect onto the iFS-1.1.9 server (running on a different unix server).
    So I copied all the necessary jar and zip files from the iFS server, installed JDK1.1.8 (would it work with JDK 1.3 since I have iFS-1.1.9 ?), put all necessary jar/zip files in the classpath and I was able to compile the sample program given in the iFS dev guide.
    I know that I also need a "service.properties" file that is in oracle.ifs.server.properties directory in my CLASSPATH, that point is ok.
    The fact is that I don't have a clue about the exact syntax of that file. I only have as an example the standard servers.properties file on my iFS server itself, but the "DatabaseUrl" attribute is probably not the same because in my case the service is running on a remote machine...
    As a result, when I launch my java app on my workstation it says :
    oracle.ifs.common.IfsException: IFS-10620: Unable to construct connection pool
    oracle.ifs.common.IfsException: IFS-10633: Unable to create library connection
    oracle.ifs.common.IfsException: IFS-10600: Unable to construct library connection
    So is there anything I am missing ? Where can I find the definition and syntax of all attributes in the .properties file ?
    Thanks in advance for any help.
    Regards,
    Arnaud.
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Thanks to your advises, here is the simple properties file I created (only 3 lines) :
    User=IFSSYS
    DatabaseUrl=jdbc:oracle:oci8:haddock/tciDir
    CredentialManagerIfsSchema=IFSSYS$CM
    <HR></BLOCKQUOTE>
    OK, so there are two problems. First of all, I should have explained better. You absolutely need ALL of the other properties in the new service properties file you have created. What I should have said in the last post was that the above three properties are the only ones you need to CHANGE. What you should do is copy IfsDefault.properties from the iFS installation ($OH/ifs1.1/settings/oracle/ifs/server/properties) to your NT machine, and then EDIT those three properties as you have specified above. And make sure to put it in the CLASSPATH correctly, under the same directory hierarchy.
    The second problem is your JDBC database URL. The format for the OCI8 connect string using a TNS alias is as follows:
    jdbc:oracle:oci8:@<tns_alias>
    where <tns_alias> is a name you create with the Oracle Net8 Assistant (it should be on your NT machine under your Start menu: Oracle-<your_oracle_home>/Network Administration).
    You should read the Net8 Administration Guide for more information about TNS aliases and how to use "thick" (OCI8) JDBC.

  • How to edit a line in a file using a batch file??????

    Basically i want to edit one line in a properties file, using a batch file, Here is what it says
    #Minecraft server properties
    #Tue Feb 22 15:58:36 PST 2011
    level-name=world2
    hellworld=false
    spawn-monsters=true
    online-mode=false
    spawn-animals=true
    max-players=5
    server-ip=5.196.238.77
    pvp=true
    server-port=25565
    white-list=false
    The IP address needs to be changed, i have a hamachi server and a server for home but i need to change this to my ip address on my computer wich is 192.168.1.74. This needs to be changed back and forth so how can i make a batch that just runs and then done its been changed.

    There are no .bat files in a Unix environment
    #!/usr/bin/env bash
    export NEW_IP=192.168.1.74
    perl -ni -e '
    s/d.d+.d+.d/$ENV{"NEW_IP"}/;
    print;
    ' yourpropertiesfile
    Make sure you change the file's protections so they are executable
    chmod +x nameof_yourscript
    There are other ways to do this, I just choose a perl script within a bash script. You could do it all with a bash script, you could use awk, you could use sed, you could use python, ruby, etc...

Maybe you are looking for

  • EXCEPTION_ACCESS_VIOLATION error in SapJCo DLL'S

    Hi All,<br><br> I have been having EXCEPTION_ACCESS_VIOLATION errors crashing the JVM in our SapJCo Client.<br><br> The error appears intermitant at the moment and we are still unable to replicate it on demand. I have found several references to simi

  • Camera Raw (via Bridge) starts to malfunction. Help!

    Windows XP Media Centre. PS CS3. This is not the first time this has happened to me. I am editing and saving images in Camera Raw via Bridge and suddenly, I cannot activate the Save Image command. The entire Camera Raw window just greys out and/or th

  • Disable Photo downloader in photoshop album starter 3.0

    When I connect my camera via USB, the photo downloader starts & ties up the camera software. Other forum topics instruct to choose edit / preferences / camera or card reader & deselect "use Adobe photo downloader to get photos from camera or reader",

  • HT1296 can i transfer music from my ipod to my computer?

    Can i transfer music from my ipod touch to my computer?

  • Permissions repair/ disk utility

    Hello: I believe I have a permissions repair problem as but I'm not entirely sure. I'm very untechnical and somewhat shakey on my conclusions and how to proceed. My computer slowed down this week after downloading freeware. I dumped all but one progr