

Filehand
Presentation
•
Computers
•
9th - 12th Grade
•
Practice Problem
•
Easy
Arasaka Teacher
Used 3+ times
FREE Resource
1 Slide • 16 Questions
1
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()
3
Drag and Drop
// 4. 将内容写入文件
4
Fill in the Blanks
Before performing any file operations, the file must be
5
Fill in the Blanks
import java.io.*;
public class ReadData {
public static void main(String[] args) {
String name = "abc.txt"; // 文件名
String line;
try (BufferedReader reader = new BufferedReader(new FileReader(name))) {
int i = 0;
// 在此处填入合适的代码,使循环能读取文件前 10 行
while (
// 读取文件中的每一行
line = reader.readLine();
// 打印出当前行内容
System.out.println(line);
i++; // 计数器增加
}
} catch (IOException e) {
e.printStackTrace(); // 捕获并打印异常
}
}
}
6
Fill in the Blanks
import java.io.*;
public class ReadAndCount {
public static void main(String[] args) {
String fileName = "test.txt";
String line;
int lineCount = 0;
int nonEmptyLineCount = 0;
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
while(lineCount < 5) && ((line = reader.readLine()) != null) {
line = reader.readLine();
if (line != null && !line.trim().isEmpty()) {
————————++
}
——————++;
}
System.out.println("非空行数量: " + nonEmptyLineCount);
} catch (IOException e) {
e.printStackTrace();
}
}
}
7
Fill in the Blanks
The command to open a file for reading is written as:
Answer:
8
Fill in the Blanks
To add data to an existing file without overwriting its contents, the file should be opened in
Answer:
9
Fill in the Blanks
The command used to read the next line of text from a file is
Answer:
10
Fill in the Blanks
The function
11
Fill in the Blanks
To close a file after it is no longer needed, use the
Answer:
12
Fill in the Blanks
Data is written into the file (after the file has been opened in WRITE or APPEND mode) using the
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 = ""
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"
15
Fill in the Blanks
Create a text file.
DECLARE myTextFile : STRING
← "myText.txt"
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)
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 = ""
By Arasaka Teacher
Show answer
Auto Play
Slide 1 / 17
SLIDE
Similar Resources on Wayground
11 questions
Le verbe Etre au présent
Presentation
•
KG
10 questions
Cause and Effect Text Structure
Presentation
•
9th - 12th Grade
14 questions
Part 4 Unlocking the Power of Visual Presentation
Presentation
•
9th - 12th Grade
12 questions
Writing Linear Equations From Two Points
Presentation
•
9th - 12th Grade
11 questions
Camera Raw
Presentation
•
9th - 12th Grade
13 questions
Chemistry of Life
Presentation
•
9th - 12th Grade
12 questions
Chap 4 Word 4.5 Formatting Pages
Presentation
•
9th - 12th Grade
13 questions
การจัดการไฟล์และ folder
Presentation
•
KG
Popular Resources on Wayground
10 questions
Safety Day 2026 – Student Review
Quiz
•
9th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
15 questions
Rounding Decimals
Quiz
•
5th Grade