It is always better to have it in a separate file, preferably in the JAR itself, so you can easily achieve it with getResourceAsStream() .
Then you can easily edit this file without using the code, and it can also be changed after the application is compiled into a JAR.
It is good practice to separate logic from data in general.
Here are some methods from my FileUtils class that you might like:
public static String streamToString(InputStream in) { BufferedReader br = null; StringBuilder sb = new StringBuilder(); String line; try { br = new BufferedReader(new InputStreamReader(in)); while ((line = br.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { Log.e(e); } finally { if (br != null) { try { br.close(); } catch (IOException e) { Log.e(e); } } } return sb.toString(); } public static InputStream stringToStream(String text) { try { return new ByteArrayInputStream(text.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { Log.e(e); return null; } } public static InputStream getResource(String path) { return FileUtils.class.getResourceAsStream(path); }
You can also use the SimpleConfig class to parse lists and maps from files:
(comment out the Log.something calls and replace System.err.println ())
package net.mightypork.rpack.utils; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class SimpleConfig { public static List<String> listFromFile(File file) throws IOException { String fileText = FileUtils.fileToString(file); return listFromString(fileText); } public static Map<String, String> mapFromFile(File file) throws IOException { String fileText = FileUtils.fileToString(file); return mapFromString(fileText); } public static List<String> listFromString(String text) { List<String> list = new ArrayList<String>(); String[] groupsLines = text.split("\n"); for (String s : groupsLines) {
source share