public static void writeF(File f){
OutputStream os = null;
String str = "文件读写";
try {
os = new FileOutputStream(f);
byte[] b = str.getBytes();
os.write(b);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("写入成功");
}
public static String readF(File f){
String str ="";
InputStream is = null;
Reader r = null;
int button = 2;
try{
switch(button){
case 1:{
System.out.println("InputStream");
is = new FileInputStream(f);
BufferedInputStream br = new BufferedInputStream(is);
byte[] b = new byte[br.available()];
br.read(b);
str = new String(b);
break;
}
case 2:{
System.out.println("Reader");
r = new FileReader(f);
BufferedReader br = new BufferedReader(r);
StringBuffer sb = new StringBuffer();
while((str = br.readLine()) != null){
sb.append(str);
}
str = new String(sb);
break;
}
}