1/4
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
In android studio, you want to open a file for reading. Assuming everything is set up properly for you to input a file of your choice, how is the file actually opened for reading? What is the code?
assetManager = getAssets();
Scanner fsc = new Scanner(assetManager.open(fileName));How is an app given permission to access the internet? What activities should be edited?
This is done in the
app’s manifest AndroidManifest.xml by including the line:
<uses-permission android:name="android.permission.INTERNET" />
I would recommend putting this entry immediately above the beginning of the “application”
element, which starts with the line:
<application
Include the following two lines in your “onCreate” method of the Main Activity:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Let’s assume you wish to write data to the file “out.txt.” To open the file for writing, use the following:
File outfile = new File(getExternalFilesDir(null), "out.txt");
FileWriter fw = new FileWriter(outfile);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
True or False: When finished writing to a file, it’s fine to not close it.
False
I.e pw.close();
What happens when you try to open an app that is nonexistent for input?
Or when it’s existent for output?
App crashes.
Original app gets clobbered and replaced