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

📄 record.java

📁 (文件数据库系统)功能强大,很有价值的代码.
💻 JAVA
字号:
import java.io.*;

public class Record{                           //key 1,int 5,string 5
	// String FileName;
;int RowId;
//	int IntFields[];
    String key;
	String attri[];
       
       
      Record(int num,String key,String str[])
       {
//		RowId=num;
//		FileName=na;
		this.key=key;
		attri=new String[num];
		for(int i=0;i<str.length;i++)
		setAttri(str[i],i);

	}
	Record(int num)
	{
//		key=0;
     attri=new String[num];
	
	}
	
	Record(Record h1,Record h2,Header he,Header he2)
	{attri=new String[he.getCount()+he2.getCount()];
		String name1=he.getName();
	String name2=he2.getName();

		setAttri(h1.getKey(),0);
		int i=0;
		for( i=0;i<h1.getLength();i++)
		setAttri(h1.getAttri(i),i+1);
			setAttri(h2.getKey(),i+1);

		for(int j=0;j<h2.getLength();j++)
		setAttri(h2.getAttri(j),i+j+2);
	}

int getLength()
{
	return attri.length;
}
		
	public  int size()
	{
		return (attri.length+1)*30+32;}
	public void setKey(String keynum)
	{
		key=keynum;
	}
	public String getKey()
	{
		return key;
	}
	
	public void setAttri(String str,int index)
	{
		attri[index]=str;
	}
	public void setRowId(int i)
	{
		RowId=i;
	}

	public String getAttri(int index)
	{
		return attri[index];
	}
	

	public void read(RandomAccessFile file) throws IOException
	{
		
		setRowId(file.readInt());
		setKey(padName(file));
		for(int i=0;i<attri.length;i++)
		setAttri(padName(file),i);
	}
		
	
	
	private String padName(RandomAccessFile file) throws IOException
	{
		char name[]=new char[15];
		char temp;
		for(int count=0;count<name.length;count++){
			temp=file.readChar();
			name[count]=temp;
		}
		return  new String(name).replace('\0',' ');
	}
			
	
	public void write(RandomAccessFile file)
	{
	try{	file.writeInt(RowId);
		writeStr(file,key);
		for(int i=0;i<attri.length;i++)
		writeStr(file,getAttri(i));}
		catch(IOException e)
		{
			System.err.println("in write");}
		
		
	}
	
	
	private void writeStr(RandomAccessFile file,String str) 
	{
		try{
		StringBuffer buffer=null;
		if(str!=null)
		buffer=new StringBuffer(str);
		else
		buffer=new StringBuffer(15);
		
		buffer.setLength(15);
		file.writeChars(buffer.toString());}
		catch(IOException e)
		{
			System.err.println("in writeStr");
	}
}	
}	

⌨️ 快捷键说明

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