Results 1 to 6 of 6
  1. #1
    maki is offline Member
    Join Date
    Sep 2013
    Posts
    42
    Rep Power
    0

    Default Changing a value in a specifing point of a specifing line in .txt file

    Hi guys, i hope this is the last thread, what I know for sure is that it is the most difficult for me and I need a big hand.

    So here we go with my problem:

    - from the main class will arrive three variabile (String name_used, int level_choosed, int level_result)
    i have a .txt file with this kind of formattation:
    mario 1 1 0 1 0 1
    carlo 0 0 0 1 1 0
    ...
    where i use 1 and 0 in the main for write if the level (you see that the numbers are always sixr? are egual to six level existing) BEFORE is done correct or wrong

    - when in the main a user make a level a feedback coming back from the class level saying if the user made the count correctly or wrong. and i wanna replace the value (1 or 0) in the txt file with the new level result.

    so i have all what i need as parameters i think.
    name_used to look for the correct line in .txt file with .indexOf
    level_choosed to go throught the correct index of that line
    level_result (1 or 2) to be replaced with the existing one



    Java Code:
    public void salvaRisultati(String name_used, int level_choosed, int result_of_level) throws FileNotFoundException{
    						
    	}
    }
    can some good man help me and try to write some code that i can use and understand.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    16

    Default Re: Changing a value in a specifing point of a specifing line in .txt file

    What's your question?

    It's hard to answer general "how do I do this" type questions other than by pointing you to google.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    maki is offline Member
    Join Date
    Sep 2013
    Posts
    42
    Rep Power
    0

    Default Re: Changing a value in a specifing point of a specifing line in .txt file

    Quote Originally Posted by maki View Post
    name_used to look for the correct line in .txt file with .indexOf
    level_choosed to go throught the correct index of that line
    level_result (1 or 2) to be replaced with the existing one



    Java Code:
    public void salvaRisultati(String name_used, int level_choosed, int result_of_level) throws FileNotFoundException{
    						
    	}
    }
    you you look at the recent thread i've made 4 class plus this one with 1 method, but for this last method i not have idea how make it, for this i'm asking if someone can help me with some code, i suppose that will be about 20 lines of code not so much.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    16

    Default Re: Changing a value in a specifing point of a specifing line in .txt file

    Which part of this is giving you trouble? Break your problem down into smaller pieces, then focus on one piece at a time.

    Can you create a separate example program that simply reads in a file?

    Can you build off that example program to read a specific line from a file?

    Go from there, and post a specific question about the specific part of the example program you're stuck on.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  5. #5
    maki is offline Member
    Join Date
    Sep 2013
    Posts
    42
    Rep Power
    0

    Default Re: Changing a value in a specifing point of a specifing line in .txt file

    excuse but do not be offended, if I was able to write it alone because I would have posted the call for help.
    If you look at the other threads I've always posted the code and interjected with other users, but here I do not know what to do. absolute zero. so if someone could write these few lines of code not only I would appreciate very much but I would also be able to learn something.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    16

    Default Re: Changing a value in a specifing point of a specifing line in .txt file

    Step one: read in the whole file.

    Step two: output what you've read in, until you reach the line you want to change.

    Step three: change the line, then output it.

    Step four: continue outputting the rest of the file.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Java- Writing a file and reading a file line by line
    By Nazneen Ali in forum New To Java
    Replies: 7
    Last Post: 07-20-2011, 08:56 AM
  2. Replies: 2
    Last Post: 03-12-2011, 05:03 PM
  3. Replies: 1
    Last Post: 02-13-2011, 04:09 PM
  4. Replies: 8
    Last Post: 12-28-2010, 03:24 PM
  5. Replies: 4
    Last Post: 09-10-2009, 11:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •