Jump to content

How to get a file from a resourcelocation?


Bedrock_Miner

Recommended Posts

Something like this works for me.  Since this contains file IO you'll have to add some try/catch exception handling:

			readIn = new BufferedReader(new InputStreamReader(getClass().getClassLoader()
				.getResourceAsStream("assets/my_mod/my_folder/myFile.txt"), "UTF-8"));
	    firstInteger = Integer.valueOf(readIn.readLine());

 

With this, I'm reading a text file.  You'd of course change the my_mod, my_folder, and myFile.txt to match your own assets directory and filename.

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

Link to comment
Share on other sites

If you want to use that code Jabelar posted with a ResourceLocation, you can use

ResourceLocation#getResourceDomain()

in place of

my_mod

, and

ResourceLocation#getResourcePath()

in place of

my_folder/myFile.txt

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

The resource manager stuff is good, except it assumes that the "asset" file you want is only to be available on the client side (IResource is client only).  For textures and sounds that is probably fine, but for example I put custom text files for things like structure generation into my assets and need them on the server side.

 

I think my original "standard Java" answer is the more general answer for reading a file you happen to put in the JAR.

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

Link to comment
Share on other sites

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.