Using Resources Folder in Unity

You can’t read the Resources directory with the StreamReader or the File class. You must use Resources.Load. 1.The path is relative to any Resources folder inside the Assets folder of your project. 2.Do not include the file extension names such as .txt, .png, .mp3 in the path parameter. 3.Use forward slashes instead of back slashes … Read more

Get OS-level system information

You can get some limited memory information from the Runtime class. It really isn’t exactly what you are looking for, but I thought I would provide it for the sake of completeness. Here is a small example. Edit: You can also get disk usage information from the java.io.File class. The disk space usage stuff requires … Read more

Android, getting resource ID from string?

@EboMike: I didn’t know that Resources.getIdentifier() existed. In my projects I used the following code to do that: public static int getResId(String resName, Class<?> c) { try { Field idField = c.getDeclaredField(resName); return idField.getInt(idField); } catch (Exception e) { e.printStackTrace(); return -1; } } It would be used like this for getting the value of … Read more

Reading a resource file from within jar

Rather than trying to address the resource as a File just ask the ClassLoader to return an InputStream for the resource instead via getResourceAsStream: try (InputStream in = getClass().getResourceAsStream(“/file.txt”); BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { // Use resource } As long as the file.txt resource is available on the classpath then this approach will … Read more

Where to place and how to read configuration resource files in servlet based application?

It’s your choice. There are basically three ways in a Java web application archive (WAR): 1. Put it in classpath So that you can load it by ClassLoader#getResourceAsStream() with a classpath-relative path: ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream input = classLoader.getResourceAsStream(“foo.properties”); // … Properties properties = new Properties(); properties.load(input); Here foo.properties is supposed to be placed … Read more