Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8398917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:09:59+00:00 2026-06-09T21:09:59+00:00

I’m getting this really annoying error. I’ve been working on it for days, as

  • 0

I’m getting this really annoying error. I’ve been working on it for days, as well as extreme amounts of research with no success. Basically, what the code is doing, is it reads the file, but it seems to remove the text after reading it. And only certain lines. This is my Reader method:

synchronized public static String getValue(String path, String filename, Boolean useColors, String folder){
    try{
        while(!TxtWriter.isResting());
        FileRequest req =  writer.getRelitive(filename, path);
        if(req==null){
            File f = new File(Conquest.FilePaths+"/"+folder, filename);
            if(!f.getParentFile().exists())f.getParentFile().mkdirs();
            if(f.exists()){
                BufferedReader in = new BufferedReader(new FileReader(f));
                String a;
                while((a=in.readLine())!=null){
                    if(a.startsWith("'"+path+"'"+":")){
                        in.close();
                        a=a.substring(path.length()+3);
                        if(useColors)a=colorCoder(a);
                        return a;
                    }
                }
                in.close();
            }else TxtWriter.createFile(filename, folder);
        }else return ((useColors)?colorCoder(req.getMessage()):req.getMessage());
    }catch(Exception e){
        System.err.println("[Conquest/TxtReader] Error reading file "+filename+"!");
        e.printStackTrace();
    }
    return null;
}

This is the file before reading:

'Kingdom':Devonel

'Flags':Leader

I call the method

public String getPlayerKingdom(String p){
    String in = TxtReader.getValue("Kingdom", p+".txt", false, "Citizens");
    return ((in==null)?in:"None");
}

It returns “None”, and the file now just has 'Flags':Leader, and nothing else.

What really puzzles me and certain methods work, while other don’t. Even when they are exactly the same code, but with different strings. This method right here is the same thing, but works just as its supposed to.

public int getResource(String kingdom, String name){
    String out = TxtReader.getValue("R-" + name, kingdom + ".txt", false, "Kingdoms");
    if(out==null)return 0;
    return Integer.valueOf(out);
}

If anyone could help, I’d be thankful. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:10:00+00:00Added an answer on June 9, 2026 at 9:10 pm

    This line looks wrong:

    return ((in==null)?in:"None");
    

    Shouldn’t it be the other way around?

    return ((in==null)?"None":in);
    

    I’m not a fan of the ternary operator construct for this very reason. Just use an if/else block and be clear about what you’re doing.

    Also, a BufferedReader will not remove information from a File. Period. It just reads in information and nothing else. If a line is being deleted, there’s likely another bug in your program, possibly in code not shown that is causing this.

    But regardless of the source of your error, your code looks very inefficient and error-prone. Why are you trying to re-read the File each time you need to check for a match? Why not simply read the file in once, and then store the information in a HashMap<String, String>?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.