日期:2014-05-20  浏览次数:20853 次

关于文件操作的两个问题,求解答!
1.查数据库表中的一个时间字段,转换成201206这种日期格式,然后以201206这字段命名创建文件夹。我在网上找了很久没有找到。
2.怎么样用程序编辑“.txt”文件,追加内容。请有例子的朋友贴出来个。
菜鸟求助感谢!

------解决方案--------------------
import java.io.*;
public class TestFile2
{
public static void main(String[] args) throws IOException
{
FileReader fr = new FileReader("ming.txt");
char[] buffer = new char[1024];
int ch = 0;
while((ch = fr.read())!=-1 )
{
System.out.print((char)ch);
}
  InputStreamReader isr = new InputStreamReader(new FileInputStream("ming.txt"));
while((ch = isr.read())!=-1)
{
System.out.print((char)ch);
}
  BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("ming.txt")));
String data = null;
while((data = br.readLine())!=null)
{
System.out.println(data);
}
  FileWriter fw = new FileWriter("hello.txt");
String s = "hello world";
fw.write(s,0,s.length());
fw.flush();
  OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("hello2.txt"));
osw.write(s,0,s.length());
osw.flush();
  PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("hello3.txt")),true);
pw.println(s);
  fr.close();
isr.close();
br.close();
fw.close();
osw.close();
pw.close();
}
}
网上好多,关于文件读写的
------解决方案--------------------
1.把txt文件用FileReader读进程序
2.加上
3.用FileWriter写出去
------解决方案--------------------
Java code

File fileDir = new File(fileDirName);
boolean makeDir = fileDir.mkdir();// 创建文件夹

------解决方案--------------------
探讨
Java code


File fileDir = new File(fileDirName);
boolean makeDir = fileDir.mkdir();// 创建文件夹



Java code


File file = new File(fileName);
Writer fw = new FileWriter(file, true);// 加true直……

------解决方案--------------------
探讨

Java code

File fileDir = new File(fileDirName);
boolean makeDir = fileDir.mkdir();// 创建文件夹


Java code

File file = new File(fileName);
Writer fw = new FileWriter(file, true);// 加true直接插入追加,不加覆盖源……