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

JAVA IO问题
读取A.tex内容删除第一个字符然后写到B.txe 在删除A.txe
能实现么?希望能给个代码!!!谢谢

------解决方案--------------------
Java code

public static void main(String[] args) {
        File fa = new File("a.txt");
        File fb = new File("b.txt");
        
        try {
            
            if(!fb.exists()){
                fb.createNewFile();
            }
            
            ObjectInputStream ois = new ObjectInputStream (new FileInputStream(fa));
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fb));
            
            char c = ois.readChar();
            oos.writeChar(c);
            
            oos.close();
            ois.close();
            
            fa.delete();
            
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

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

Java code

public static void main(String[] args) {
File fa = new File("a.txt");
File fb = new File("b.txt");

try {

if(!fb.exists()){
……