-
-
Save anta40/1c24d0dc724ae63f10a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* I use this method to get contents of JSON formatted file that I put into res | |
* directory to deliver default data for my application. | |
* Visit my blog at http://web.durianapp.com | |
*/ | |
public static String getResFileContent(String filename) { | |
InputStream is = null; | |
try { | |
if (klas == null) { | |
klas = Class.forName("com.durianapp.brandapp.BrandApp"); | |
} | |
is = klas.getResourceAsStream(filename); | |
byte[] bytes = new byte[1024]; | |
int len = 0; | |
StringBuffer buf = new StringBuffer(); | |
while ((len = is.read(bytes)) != -1) { | |
buf.append(new String(bytes, 0, len)); | |
} | |
return buf.toString(); | |
} catch(Exception ex) { | |
System.out.println("Error: " + ex.toString()); | |
return ""; | |
} finally { | |
try { | |
if (is != null) is.close(); | |
} catch (Exception e) { | |
System.out.println("Ex: "+e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment