ex_2.java
来自「JAVA分布式程序学习的课件(全英文)」· Java 代码 · 共 39 行
JAVA
39 行
// Based on Holmes chap_4 Ex_7
// program to read data from a file till the end of file, modify the
// information and write the information back to a different text file
import java.io.*;
class Ex_2
{
public static void main(String[] args) throws IOException
{
final float RATE_OF_INFLATION = 0.025f;
FileReader file1 = new FileReader("data.txt");
BufferedReader inputFile = new BufferedReader(file1);
FileWriter file2 = new FileWriter("results.txt");
PrintWriter outputFile = new PrintWriter(file2);
String name;
String theLine;
float oldprice, newprice;
theLine = inputFile.readLine();
while (theLine != null) // while EOF has not been reached
{
oldprice = new Float(theLine).floatValue();
newprice = oldprice + (oldprice * RATE_OF_INFLATION);
name = inputFile.readLine();
outputFile.println(newprice + " " + name);
theLine = inputFile.readLine();
}
inputFile.close();
outputFile.close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?