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

📄 linerw.java

📁 采用Eclipse开发的学生成绩管理系统,可以添加班级,人员,数据没有采用数据库,后台采用文本文件的形式存储,可以很方便的改为数据库.
💻 JAVA
字号:
package file;
import java.io.*;
import java.util.*;
public class LineRW{
     File file1;
     File file2;
     File file3;
     File file4;
    public void write(String s){
    	RandomAccessFile raf;
    	int i;
    	try{
        String es="\n";
        char cno=s.charAt( 0);
        switch(cno){
        	case '1':
        		i=1;
        		file1=new File(".","xsjb1.txt");
        	    raf=new RandomAccessFile(file1,"rw");
        		break;
        	case '2':
        		i=2;
        		file2=new File(".","xsjb2.txt");
        		raf=new RandomAccessFile(file2,"rw");
        		break;
        	case '3':
        		i=3;
        		file3=new File(".","xsjb3.txt");
        		raf=new RandomAccessFile(file3,"rw");
        		break;
        	default:
        		i=4;
        		file4=new File(".","xsjb4.txt");
        		raf=new RandomAccessFile(file4,"rw");
        		break;
        }
        
        raf.seek( raf.length() );
        s=s+es;
        raf.writeBytes (s);
        raf.close();
        VectorOperate vo=new VectorOperate(cno-48);
        Vector v=vo.getV() ;
    	}
    	catch(Exception e){
    		System.out.println(e+"this is in LineRW write");
    	}
    }
    public void read(int i){
    	try{
    	RandomAccessFile raf;
        switch( i){
    	case 1:
    	    raf=new RandomAccessFile(file1,"r");
    		break;
    	case 2:
    		raf=new RandomAccessFile(file2,"r");
    		break;
    	case 3:
    		raf=new RandomAccessFile(file3,"r");
    		break;
    	default:
    		raf=new RandomAccessFile(file4,"r");
    		break;
        }
        while(raf.getFilePointer() !=raf.length() ){
        		System.out.println(raf.readLine());       
        }
        raf.close() ;
    	}
    	catch(Exception e){
    		System.out.println(e+"this is in LineRW read");
    	}
    }
    public void delect(String cno,String sno){
    	long start=0,lastStart=0;
    	long length=0;
    	String str;
    	boolean flag=false;
    	String id=cno.concat( sno) ;
    	
    	RandomAccessFile raf;
    	File file;

    	try{		
            if(cno.equals( "1")){

        		file1=new File(".","xsjb1.txt");
        		raf=new RandomAccessFile(file1,"rw");

           }
        	else if(cno.equals( "2")){
        		file2=new File(".","xsjb2.txt");
        		raf=new RandomAccessFile(file2,"rw");
        	}
        		else if(cno.equals( "3")){

        			file3=new File(".","xsjb3.txt");
        		    raf=new RandomAccessFile(file3,"rw");
        		}
        		    else {

        				file4=new File(".","xsjb4.txt");
        				raf=new RandomAccessFile(file4,"rw");
        		    }  
        VectorOperate vo=new VectorOperate(Integer.parseInt( cno));
        Vector v=vo.getV() ;
		for(int i=0;i<v.size() ;i++){
			InfoOfLine iole=(InfoOfLine)v.elementAt( i);
			if(Long.parseLong(id)==iole.id  ){
				start=iole.start ;
				flag=true;
				break;
			}
		}
	if(flag==true){
		InfoOfLine iol=(InfoOfLine)v.lastElement(); 
    	lastStart=iol.start;
    	raf.seek(lastStart);
    	str=raf.readLine()+"\n" ;
    	length=str.length() ;
    	raf.seek(start);
    	raf.writeBytes( str);
    	raf.seek(lastStart);
    	raf.writeBytes( "                                         \n");
    	raf.setLength(lastStart);
    	raf.close() ;
		}
        vo=new VectorOperate(Integer.parseInt( cno));
    	}
	catch(Exception ee){
		System.out.println(ee+"this is in LineRW delect");
	}
    } 
}

⌨️ 快捷键说明

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