文件管理系统实现Word格式.docx
《文件管理系统实现Word格式.docx》由会员分享,可在线阅读,更多相关《文件管理系统实现Word格式.docx(28页珍藏版)》请在冰点文库上搜索。
![文件管理系统实现Word格式.docx](https://file1.bingdoc.com/fileroot1/2023-4/29/aa47e5b5-686d-40ae-b082-7d94e2a1dc02/aa47e5b5-686d-40ae-b082-7d94e2a1dc021.gif)
if(name.getBytes().length>
=6){
this.name=name.substring(0,6);
}
else{
while(name.getBytes().length<
6){
name+='
\u0000'
;
}
this.name=name;
//this.name=name;
}
publicStringgetName(){
returnname;
publicvoidsetName(Stringname){
this.name=name;
publicintgetType(){
returntype;
publicvoidsetType(inttype){
this.type=type;
publicintgetSize(){
returnsize;
publicvoidsetSize(intsize){
this.size=size;
publicStringgetCal(){
returncal;
publicvoidsetCal(Stringcal){
this.cal=cal;
publicintgetFirstblock(){
returnfirstblock;
publicvoidsetFirstblock(intfirstblock){
this.firstblock=firstblock;
}
importjava.io.BufferedReader;
importjava.io.DataOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.io.ObjectOutputStream;
importjava.io.RandomAccessFile;
classOS{
staticBufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
staticStringcurrent_directory="
"
finalstaticintEMPTY_BLOCK=0xFFFE;
finalstaticintLAST_BLOCK=0xFFFF;
finalstaticintBLOCK_SIZE=1024;
staticintfirstblock=0;
staticintblockcount;
staticStringfilename="
staticRandomAccessFileraf1;
staticObjectOutputStreamoos;
staticFileOutputStreamfos;
staticDataOutputStreamdos;
staticFilefile;
staticintf=0;
//fat表中的块号
staticintblock=0;
//写块号与mdmkFCB写入块中
staticintblockno=0;
//读块号
staticinttimes=0;
publicstaticvoidmain(String[]args)throwsException{
while(true){
Stringcmd="
System.out.print(current_directory);
System.out.print("
$:
);
try{
cmd=br.readLine();
if((cmd.indexOf("
exit"
))!
=-1){
break;
}
elseif(cmd.indexOf("
dir"
)!
dir(cmd);
md"
md(cmd);
cd"
cd(cmd);
rd"
rd(cmd);
mk"
mk(cmd);
del"
del(cmd);
format"
format(cmd);
fat"
fat();
info"
Stringstr=cmd.substring(5);
inti=Integer.parseInt(str);
info(i);
help"
help();
exit();
else{
System.out.println("
errorcommand!
}catch(Exceptione){
System.out.println(e);
publicstaticvoiddir(Stringcmd)throwsException{
inti=current_directory.length();
Stringstr="
if(i>
0){
str=current_directory.substring(0,i-1);
StringBuffersb=newStringBuffer(str);
intj=sb.lastIndexOf("
/"
Strings1=str.substring(j+1);
//System.out.println("
blockno========"
+blockno);
raf1=newRandomAccessFile(file,"
r"
raf1.seek(blockno*1024+blockcount*2);
//System.out.println("
-------------"
+(blockno*1024+16));
byte[]b=newbyte[6];
byte[]b1=newbyte[14];
intByteCount=0;
raf1.read(b);
Strings2=newString(b);
if(ByteCount!
=1024){
//System.out.println(judge(b));
//System.out.println(s2);
if(!
judge(b)){
inttype=raf1.readInt();
intsize=raf1.readInt();
//System.out.println("
size======"
+size);
raf1.read(b1);
Strings3=newString(b1);
intfirstblock=raf1.readInt();
//System.out.println("
tyep======"
+type);
firstblock========"
+firstblock);
System.out.println(s3+"
"
+"
<
DIR>
+size+"
+s2);
ByteCount======"
+ByteCount);
raf1.skipBytes(26);
ByteCount+=32;
else{
break;
publicstaticbooleanjudge(byte[]b){
for(inti=0;
i<
b.length;
i++){
if(b[i]!
=0){
returnfalse;
continue;
returntrue;
publicstaticvoidmd(Stringcmd){
Stringstr=cmd.substring(3);
try{
//System.out.println("
strr==========="
+str);
byte[]by={(byte)0xFFFF};
raf1=newRandomAccessFile(file,"
rw"
raf1.seek(blockno*1024+block);
//System.out.println(!
sameName(str,blockno*1024+block));
//intn=blockno*1024+16;
if(!
sameName(str,blockno*1024+blockcount*2)){
//System.out.println("
blcok====="
+(blockno*1024+block));
block+=32;
FCBfcb=newFCB(str);
Calendarcal=Calendar.getInstance();
fcb.type=1;
fcb.size=1024;
Stringstr1=cal.get(Calendar.YEAR)+"
+(cal.get(Calendar.MONTH)+1)+"
+cal.get(Calendar.DAY_OF_MONTH)
+"
+cal.get(Calendar.HOUR_OF_DAY)+"
+cal.get(Calendar.MINUTE)+"
-"
+cal.get(Calendar.SECOND);
if(str1.length()>
14){
str1=str1.substring(0,14);
while(str1.getBytes().length<
str1+='
//System.out.println(str1.length());
fcb.cal=str1;
fcb.firstblock=firstblock;
//System.out.println("
first======"
++firstblock;
//System.out.println("
sencond++=="
//oos.writeObject(f);
raf1.write(fcb.getName().getBytes());
raf1.writeInt(fcb.getType());
raf1.writeInt(fcb.getSize());
//System.out.println("
fcb.getCal().getBytes().length"
+fcb.getCal().getBytes().length);
raf1.write(fcb.getCal().getBytes());
//System.out.println("
fcb.getCal().getBytes()====="
raf1.writeInt(fcb.getFirstblock());
++times;
raf1.seek(f);
raf1.write(by);
raf1.write(by);
f+=2;
//System.out.println(f);
raf1.close();
System.out.println("
创建成功"
此文件已经存在,请换个名字创建"
return;
}catch(FileNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(IOExceptione){
publicstaticbooleansameName(Stringstr,intn){
RandomAccessFileraf2=newRandomAccessFile(file,"
intByteCount=0;
byte[]b=newbyte[6];
raf2.seek(n);
while(true){
raf2.read(b);
Strings=newString(b);
str========"
s======="
+s);
//System.out.println(str+"
="
+str.length());
//System.out.println(s+"
="
+s.length());
BYcoutn========="
//System.out.println(compare(str,s));
if(ByteCount!
if(compare(str,s)){
returntrue;
}
else{
raf2.skipBytes(26);
ByteCount+=32;
returnfalse;
returnfalse;
publicstaticvoidcd(Stringcmd)throwsException{
raf1=newRandomAccessFile(file,"
//raf1.skipBytes(blockcount*2-1);
//Strings1="
Strings4="
if(str.equals("
)||str.equals("
.."
)){
blockno=0;
current_directory="
block=findBlock()*32+blockcount*2;
//System.out.println(block);
times=0;
return;
inta=blockno*1024+blockcount*2;
raf1.seek(a);
blockcount====="
+blockcount*2);
Strings1=newString(b);
if(s1.indexOf(str)!
raf1.skipBytes(22);
intc=raf1.readInt();
blockno=c;
blockno======="
current_directory+=str;
current_directory+="
block-=times*32;
times=0;
helloiaminhere"
//raf1.seek(blockcount*2+32);
raf1.skipBytes(26);
publicstaticintfindBlock()throwsException{
RandomAccessFileraf2=newRandomAccessFile(file,"
raf2.seek(blockcount*2);
intblock1=0;
raf2.read(b);
Stringstr=newString(b);
//System.out.println("
str="
block1="
+block1);
//System.out.println(judge(b));
raf2.skipBytes(26);
++block1;
returnblock1;
publicstaticvoidrd(Stringcmd)throwsException{
raf1=newRandomAccessFile(file,"
byte[]b2={0};
//inttime=0;
//System.out.println(blockno*1024+16);
//System.out.println(s2.indexOf(str)!
=-1);
if(s2.indexOf(str)!
//if(comp