黑马程序员技术交流社区
标题:
我这个哪里有问题
[打印本页]
作者:
ccluck11
时间:
2017-2-8 13:30
标题:
我这个哪里有问题
package com.heima.bean;
import java.io.IOException;
public interface MyRead {
public void readTxt() throws IOException;
}
package com.heima.bean;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class MyIO implements MyRead {
private File file;
public MyIO() {
super();
}
public MyIO(File file) {
super();
this.file = file;
}
@Override
public void readTxt() throws IOException {
BufferedReader br= new BufferedReader(new FileReader(file));
int b;
while((b = br.read()) != -1) {
System.out.println((char)b);
}
}
}
package com.heima.bean;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class UseOnlyTen implements MyRead{
private MyIO m ;
public UseOnlyTen() {
super();
}
public UseOnlyTen(MyIO m) {
super();
this.m = m;
}
@Override
public void readTxt() throws IOException {
BufferedReader br = new BufferedReader(new FileReader("config.txt"));
String s = br.readLine();
int count = Integer.parseInt(s);
br.close();
if(count > 0) {
m.readTxt();
count--;
System.out.println("你还有"+count+"次机会");
BufferedWriter bw = new BufferedWriter(new FileWriter("config.txt"));
bw.write(count);
bw.close();
}else {
System.out.println("请购买正版");
}
}
}
package com.heima.test;
import java.io.File;
import java.io.IOException;
import com.heima.bean.MyIO;
import com.heima.bean.UseOnlyTen;
public class test1 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
UseOnlyTen o = new UseOnlyTen(new MyIO(new File("xxx.txt")));
o.readTxt();
}
}
作者:
yourtear
时间:
2017-2-8 21:41
111111111111111
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2