Last active
April 19, 2018 20:24
-
-
Save DevPicon/be45008af3c43c23b7d7eb4baf12b16d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.io.BufferedReader; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
public class ParseMockJson { | |
public static String readFromfile(String filename) { | |
StringBuilder returnString = new StringBuilder(); | |
InputStream fIn = null; | |
InputStreamReader isr = null; | |
BufferedReader input = null; | |
try { | |
fIn = SessionData.getContext().getResources().getAssets().open(filename); | |
isr = new InputStreamReader(fIn); | |
input = new BufferedReader(isr); | |
String line = ""; | |
while ((line = input.readLine()) != null) { | |
returnString.append(line); | |
} | |
} catch (Exception e) { | |
e.getMessage(); | |
} finally { | |
try { | |
if (isr != null) | |
isr.close(); | |
if (fIn != null) | |
fIn.close(); | |
if (input != null) | |
input.close(); | |
} catch (Exception e2) { | |
e2.getMessage(); | |
} | |
} | |
return returnString.toString(); | |
} | |
} |
This file contains hidden or 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
String str = ReadFromfile(); | |
Gson gson = new Gson(); | |
Forms form = gson.fromJson(str, Forms.class); | |
onFormSuccess(form); | |
public String ReadFromfile(){ | |
StringBuilder returnString = new StringBuilder(); | |
InputStream fIn = null; | |
InputStreamReader isr = null; | |
BufferedReader input = null; | |
try { | |
fIn = AppContext.getInstance().getContext().getResources().getAssets() .open("updatecreditcards.json"); | |
isr = new InputStreamReader(fIn); | |
input = new BufferedReader(isr); | |
String line = ""; | |
while ((line = input.readLine()) != null) { | |
returnString.append(line); | |
} | |
} catch (Exception e) { | |
e.getMessage(); | |
} finally { | |
try { | |
if (isr != null) | |
isr.close(); | |
if (fIn != null) | |
fIn.close(); | |
if (input != null) | |
input.close(); | |
} catch (Exception e2) { | |
e2.getMessage(); | |
} | |
} | |
return returnString.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment