IT114 Input Output Files

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/4

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:16 PM on 3/5/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

5 Terms

1
New cards

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));


2
New cards

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);

3
New cards

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);

4
New cards

True or False: When finished writing to a file, it’s fine to not close it.

False

I.e pw.close();

5
New cards

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