Search Header Logo
Filehand

Filehand

Assessment

Presentation

Computers

9th - 12th Grade

Practice Problem

Easy

Created by

Arasaka Teacher

Used 3+ times

FREE Resource

1 Slide • 16 Questions

1

File

By Arasaka Teacher

2

Reorder

String name = "abc.txt";
File file = new File(name);
System.out.println(file.exists());
try {
// 使用 FileReader 打开文件
使用 BufferedReader 包装 FileReader,提高读取效率
// 用于存储从文件中读取的每一行内容
String line;
// 先读取一行

//条件是什么



{
// 输出当前行
System.out.println(line);
// 读取下一行
line = reader.readLine();
}
} ; // 处理异常
}

FileReader fileReader = new FileReader(file);

BufferedReader reader = new BufferedReader(fileReader);

line = reader.readLine();

while (line != null)

catch (IOException e) {
e.printStackTrace()

1
2
3
4
5

3

Drag and Drop

// 1. 使用 File 类创建文件对象





// 4. 将内容写入文件

// 写入多行内容





;

Drag these tiles and drop them in the correct blank above
File file = new File(name);
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(content);
File file = new File();
FileWriter fileWriter = new FileWriter();
fileWriter.append(content);
fileWriter.close()

4

Fill in the Blanks

5

Fill in the Blanks

6

Fill in the Blanks

7

Fill in the Blanks

8

Fill in the Blanks

9

Fill in the Blanks

10

Fill in the Blanks

11

Fill in the Blanks

12

Fill in the Blanks

13

Reorder

Write several lines of text to the file.

DECLARE textLn : STRING

DECLARE myFile : STRING

myFile ← "myText.txt"

REPEAT

    OUTPUT "Please enter a line of text"

  

IF textLn <> ""

    THEN

       

    ELSE

      

    ENDIF

OUTPUT "The file contains these lines of text:"

OPEN myFile FOR WRITE

  INPUT textLn

 WRITEFILE myFile, textLn

  CLOSEFILE(myFile)

UNTIL textLn = ""

1
2
3
4
5

14

Reorder

This example uses the operations together, to copy all the lines from FileA.txt to FileB.txt,

replacing any blank lines by a line of dashes.

DECLARE LineOfText : STRING

OPENFILE "FileA.txt" FOR READ

OPENFILE "FileB.txt" FOR WRITE

WHILE NOT EOF("FileA.txt")

READFILE "FileA.txt", LineOfText

IF LineOfText = "" THEN

WRITEFILE "FileB.txt", " ----------------------------"

ELSE

WRITEFILE "FileB.txt", LineOfText

ENDIF

ENDWHILE

CLOSEFILE "FileA.txt"

CLOSEFILE "FileB.txt"

1
2
3
4
5

15

Fill in the Blanks

16

Reorder

Reorder the following

OUTPUT "The file contains these lines of text:"

REPEAT

OPEN myTextFile FOR READ

    READFILE, textIn

    OUTPUT textIn

UNTIL EOF(myTextFile)

CLOSEFILE(myTextFile)

1
2
3
4
5

17

Reorder

Append a line of text at the end of the file.

DECLARE textIn : STRING

REPEAT

   

       

    ELSE

   

OPEN myTextFile FOR APPEND

    OUTPUT "Please enter a line of text"

    INPUT textIn

 IF textIn <> "" THEN

 WRITEFILE, textIn

     CLOSEFILE(myTextFile)

    ENDIF

UNTIL textIn = ""

1
2
3
4
5

File

By Arasaka Teacher

Show answer

Auto Play

Slide 1 / 17

SLIDE