Skip to content

Instantly share code, notes, and snippets.

@DevPicon
Last active April 19, 2018 20:24
Show Gist options
  • Save DevPicon/be45008af3c43c23b7d7eb4baf12b16d to your computer and use it in GitHub Desktop.
Save DevPicon/be45008af3c43c23b7d7eb4baf12b16d to your computer and use it in GitHub Desktop.
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();
}
}
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