展开全部
public static void main(String[] args) {
try {
File file=new File("E:\\javaIO\\");
if(!62616964757a686964616fe4b893e5b19e31333337616531file.exists()){
file.mkdirs();
}
File login=new File("E:\\javaIO\\login.txt");
if(!login.exists()){
login.createNewFile();
}
File exercise=new File("E:\\javaIO\\exercise.txt");
if(!exercise.exists()){
exercise.createNewFile();
}
File[] fs=file.listFiles();
for(int i=0;i
System.out.println(fs[i].getName());
}
String str="asdasasd\nccccc\nvvvvv\n";
out(login,str);
str=in(login);
out(exercise, str);
str=in(exercise);
System.out.println(str);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String in(File file) throws IOException{
FileInputStream in=new FileInputStream(file);
InputStreamReader inr=new InputStreamReader(in,"utf-8");
BufferedReader re=new BufferedReader(inr);
String loginStr="";
String temp=null;
while((temp=re.readLine())!=null){
loginStr+=temp+"\n";
}
re.close();
inr.close();
in.close();
return loginStr;
}
public static void out(File file,String str) throws IOException{
FileOutputStream out=new FileOutputStream(file);
OutputStreamWriter we=new OutputStreamWriter(out, "utf-8");
we.write(str);
we.close();
out.close();
}
本水货的代码,语法烂了点,见谅