版权声明:版权所有@万星明 https://blog.csdn.net/qq_19533277/article/details/83242901
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
* @author 万星明
* @version 创建时间:2018年10月20日 上午9:45:07
* 3、请用PrintWriter类,将九九乘法表按正确格式输出到指定的文件上
* 4、将第3题写出的乘法表内容,通过IO读取,打印在控制台显示
*/
public class Work3 {
public static void main(String[] args) throws Exception {
File file = new File("99乘法表.txt");
// printMultip(file);
readFile(file);
}
public static void printMultip(File file) throws Exception {
PrintWriter pw = new PrintWriter(file);
String s = null;
for(int i=1;i<=9;i++) {
for(int j=1;j<=i;j++) {
s = (j+"*"+i+"="+i*j+"\t");
pw.write(s);
}
pw.write("\t\n");
}
pw.close();
}
public static void readFile(File file) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String s=br.readLine();
while(s!=null) {
System.out.println(s);
s=br.readLine();
}
br.close();
}
}