F:\
\test
\111.txt
\444.txt
\aa
\aa.txt
按照这文件的路径打印:
Demo类:
package jiujiu;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class Jiu {
public void Dayin(String filedy){
for(int i=1;i<=9;i++){
for(int j=1;j<=i;j++){
if(i%2==1){
int ji=j*i;
String str1=j+”*”+i+”=”+ji+” “;
writefile(str1,filedy);
}else{
}
}
String str2="\r\n";
writefile(str2,filedy);
}
}
private void writefile(String data,String filedy) {
// TODO Auto-generated method stub
File file=new File(filedy);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
OutputStream os=null;
try {
os=new FileOutputStream(file,true);
byte[]bytes=data.getBytes();
os.write(bytes);
os.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(os!=null){
os.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args){
Jiu jiu=new Jiu();
jiu.Dayin("f:/test/444.txt");
}
}
定义GetFileDemo类: