⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appendtext.java

📁 Java案例开发集锦,里面提供了很好的学习例子
💻 JAVA
字号:
/**
*本案例利用RandomAccessFile类的length()和seek()方法,
*轻松实现文本的追加
**/
import java.io.*;
public class AppendText { 
  public static void main(String[] args) {
    try{ 
    RandomAccessFile rf1 = new RandomAccessFile("d:\\chapter6\\test.txt","rw"); 
    for (int i = 0; i<10; i++){ 
      rf1.writeBytes("xixi,this is line"+i+"\n"); 
    } 
    rf1.close(); 
    int i = 0; 
    String record = new String(); 
    RandomAccessFile rf2 = new RandomAccessFile("d:\\chapter6\\test.txt","rw"); 
    rf2.seek(rf2.length()); 
    rf2.writeBytes("lala,append line"+"\n"); 
    rf2.close(); 
    RandomAccessFile rf3 = new RandomAccessFile("d:\\chapter6\\test.txt","r"); 
    while ((record = rf3.readLine()) != null) { 
      i++; 
      System.out.println("Value "+i+":"+record); 
    } 
    rf3.close(); 
    }catch(Exception e){} 
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -