Jump to content

May be deleted for uselessness, but this path isn't working


Recommended Posts

Posted

I'm trying to load a text file into a large string variable instead of hard-coding it. That seemed straightforward until no paths worked. I'm trying to use this:

String pageString = new String(Files.readAllBytes(Paths.get("/assets/vmc/BookPages/" + pageID + ".json")));

and I'm pretty sure there's a file there, but it's telling me that there isn't.

I've also tried the following:

"/assets/vmc/BookPages/" + pageID + ".json"

MODID + "/BookPages/" + pageID + ".json"

"assets/vmc/BookPages/" + pageID + ".json"

I've been trying at this for way too long now, and need some sleep. I'll be back to respond tomorrow.

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Posted

You can't do it like this. Even if you did get it working, it wound fall the moment you compiled your mod into a jar because then your assets don't exist as files on the drive, but contents of a zipped file. 

 

This code may help:

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/CogHelper.java#L56

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I'm having a hard time understanding what this is doing. What is HardLib and why are you getting its runtime class? How do you go from byte array to something usable? I see the toString method there, but also on the bufferedReader.

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Posted
56 minutes ago, Zane49er said:

I'm having a hard time understanding what this is doing. What is HardLib and why are you getting its runtime class?

HardLib is a "main mod class." I could have done "this" as well. 

And because I need to get is class loader. From which I then call getResourceAsStream()

56 minutes ago, Zane49er said:

How do you go from byte array to something usable? I see the toString method there, but also on the bufferedReader.

The byte array holds data between the buffer reader and the buffet writer. Lines 62 and 64. The buyer writer in this case being to a normal File object. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
String resourceName = "/assets/vmc/BookPages/" + pageID + ".json";
		BufferedReader pageScan = new BufferedReader(new InputStreamReader(getClass().getClassLoader ().getResourceAsStream(resourceName), "UTF-8"));
		String pageString = "";
		while(pageScan.ready()){
			pageString += pageScan.readLine();
		}
		JsonObject pageData = new Gson().fromJson(ResourceManager.getString(pageString), JsonObject.class);
		pageName = pageData.get("name").getAsString();

I guess I should explain why I'm doing this.

Before attempting to make this .json file into a string, I was reading a plain text file and reading each line into a variable in an object in an array. The text files obviously started to get really ugly, so I wanted to format it as JSON, which is exactly the format that I was emulating with the arrays. GSON made this mostly easy except that it needs  a string for an input. Is there a way I can get this JSON document into a string, or am I missing something that would make this much easier?

The code above causes nullpointerexception crash from the inputStreamReader on the second line, which was previously working fine.

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Posted

Thanks. I'm surprised I didn't notice that. The first slash was the cause of the crash, removing it gives the exact result I want:

		String resourceName = "assets/vmc/BookPages/" + pageID + ".json";
		BufferedReader pageScan = new BufferedReader(new InputStreamReader(getClass().getClassLoader ().getResourceAsStream(resourceName), "UTF-8"));
		JsonObject pageData = new Gson().fromJson(pageScan, JsonObject.class);
		pageName = pageData.get("name").getAsString();

 

Lord Volkihar has requested that I send the following message to everyone who is gifted, intellectually or artistically:

We hope that some people could help us share an epic tale of lord Volkihar's achievements and magnificent life. we plan to do this through modern media such as books, games, and mods.

For lost details, we are looking for around 5 gallons of Cortexiphan, and some N.Z.T.(around 50 pills) also, if you happen to know how to create a gel with the same density as human flesh, but low viscosity and adhesion, recipes would be appreciated.

Posted

This kind of code has worked for me before. In this case I was reading in an array of blocks that had integer positions and the unlocalized block names. The size of the file was indicated by the first three integers which defined the size of the array, but you may need to do your own end-of-file detection depending on your file format. The main thing I wanted to show was how I created the buffered reader.

:

    public void readArrays(String parName)
    {
        try 
        {
            System.out.println("Reading file = "+parName+".txt");
            readIn = new BufferedReader(new InputStreamReader(getClass().getClassLoader()
                    .getResourceAsStream("assets/magicbeans/structures/"+parName+".txt"), "UTF-8"));
            dimX = Integer.valueOf(readIn.readLine());
            dimY = Integer.valueOf(readIn.readLine());
            dimZ = Integer.valueOf(readIn.readLine());
            blockNameArray = new String[dimX][dimY][dimZ];
            blockMetaArray = new int[dimX][dimY][dimZ];
            System.out.println("Dimensions of structure = "+dimX+", "+dimY+", "+dimZ);
            for (int indY = 0; indY < dimY; indY++) // Y first to organize in vertical layers
            {
                for (int indX = 0; indX < dimX; indX++)
                {
                    for (int indZ = 0; indZ < dimZ; indZ++)
                    {
                        blockNameArray[indX][indY][indZ] = readIn.readLine();
                        blockMetaArray[indX][indY][indZ] = Integer.valueOf(readIn.readLine());
                    }
                }
            }
        } 
        catch (FileNotFoundException e) 
        {
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }
        
        try 
        {
            readIn.close();
        } 
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.