package com.javabase.sss;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
import javax.security.auth.login.FailedLoginException;
public class Demofile {
//获取java类的所有方法并打印出来
public static void sgetMethod() {
Class c = File.class;
Method[] m =c.getMethods();
for (int i = 0; i < m.length; i++) {
System.out.println(m[i].getName());
}
}
public static void main(String[] args) {
File file = new File("C:/1122.txt");
FileWriter fw = null;
if(!file.exists()) {
try {
if(file.createNewFile()) {
System.out.println("创建文件成功");
System.out.println("文件绝对路径: " + file.getAbsolutePath());
}
} catch (IOException e) {
e.printStackTrace();
}
}else {
System.out.println("文件名已经存在");
}
//文件存在就写数据
try {
String s = "我想去南海看海! ";
fw = new FileWriter(file,true);
for (int i = 0; i < 100; i++) {
fw.write(s);
}
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
java中File类的操作
猜你喜欢
转载自blog.csdn.net/qq_43314793/article/details/90053845
今日推荐
周排行