Java实现读取某个路径下的文件目录

2021-01-26 11:27:15 字数 4606 阅读 9938

1楼:匿名用户

importjavax.swing.*;

importjavax.swing.table.abstracttablemodel;

importjavax.swing.table.tablecellrenderer;

importjavax.swing.event.treemodellistener;

importjavax.swing.event.treeselectionlistener;

importjavax.swing.event.treeselectionevent;

importjavax.swing.tree.treemodel;

importjavax.swing.tree.treepath;

importjavax.swing.tree.treecellrenderer;

importjava.awt.*;

importjava.awt.event.*;

importjava.io.file;

importjava.io.fileinputstream;

importjava.io.ioexception;

importjava.io.filefilter;

importjava.util.calendar;

importjava.util.arraylist;

importjava.text.******dateformat;

importjava.text.messageformat;

/***@authorhardneedl

*/classjavaexplorerextendsjframe

publicdimensiongetminimumsize()

publicdimensiongetpreferredsize()

publicstringgettitle()

javaexplorer()throwsheadles***ception

privatevoidinit()};

tree=newjtree(newfiletreemodel());

tree.setcellrenderer(newdircellrenderer());

detailtable=newjtable(tablemodel=newfiletablemodel());

detailtable.getcolumnmodel().getcolumn(2).setcellrenderer(newtablecellrenderer()

returnlabel;

}});

detailtable.getcolumnmodel().getcolumn(0).setcellrenderer(newtablecellrenderer()

returnlabel;

}});

}privatevoiddolay()

privatevoidattachlisteners()

publicstaticvoidmain(stringargs)

privateclassfiletreemodelimplementstreemodel

};privatefiletreemodel()

publicobjectgetroot()

publicobjectgetchild(objectparent,intindex)

returnnull;

}publicintgetchildcount(objectparent)

return0;

}publicbooleanisleaf(objectnode)

publicvoidvalueforpathchanged(treepathpath,objectnewvalue){}

publicvoidaddtreemodellistener(treemodellistenerl){}

publicvoidremovetreemodellistener(treemodellistenerl){}

publicintgetindexofchild(objectparent,objectchild)

if(parentinstanceoffile)

}return-1;}}

privateclassfiletablemodelextendsabstracttablemodel

publicintgetcolumncount()

privatefiledir;

privatevoidsetdir(filedir)

publicclassgetcolumnclass(intcolumnindex)

}publicstringgetcolumnname(intcolumn)

}publicobjectgetvalueat(introwindex,intcolumnindex)catch(ioexceptione)

case2:

calendarcl=calendar.getinstance();

cl.settimeinmillis(f.lastmodified());

returncl;

}returnnull;}}

privateclass_dirselectionlistenerimplementstreeselectionlistener个文件",fs.length));

}else

statuslabel.settext(null);}}

}privateclassdircellrendererextendsjlabelimplementstreecellrenderer

public***ponentgettreecellrenderer***ponent(jtreetree,objectvalue,booleanselected,booleanexpanded,booleanleaf,introw,booleanhasfocus)

else

settext(value.tostring());

setforeground(selected?color.blue:color.black);

setbackground(selected?color.yellow:color.white);

returnthis;}}

privateclassselectionlistenerimplementstreeselectionlistener}}

privateclassdircellselectedlistenerimplementskeylistener,mouselistener

privatevoidaction(inputevente)

if(einstanceofkeyevent)

}privatevoidexpand(filef)

treepathtreepath=newtreepath(filetreemodel.root);

for(inti=l.size()-1;i>-1;i--)

tree.setselectionpath(treepath);}}

publicvoidkeytyped(keyevente){}

publicvoidkeypressed(keyevente)}}

publicvoidkeyreleased(keyevente)

publicvoidmouseclicked(mouseevente)}}

}publicvoidmousepressed(mouseevente)

publicvoidmousereleased(mouseevente)

publicvoidmouseentered(mouseevente)

publicvoidmouseexited(mouseevente)}}

java实现:如何读取一个文本,通过里面的文件路径读取文件内容

2楼:匿名用户

public class test

public static void readfilebychars(string filename) else else }}

}}} catch (exception e1) finally catch (ioexception e1) }}}}

3楼:匿名用户

activexobject("scripting.filesystemobject")

这个是 activex ,好像只有ie才支持这个技术吧而且即使是ie,也是受到安全限制的。

你可以考虑采用 xmlhttp 对象(这个是目前各种主流浏览器都有的)来读取 文本的内容。。但是 无法逐行读取,如果文本很大的话。。将会成为程序的瓶颈。。请参考

4楼:喝着拿铁吃烧饼

kejiaweiren 说的很好..

流星蝴蝶剑目录下每个文件都是干什么的

1楼 丶罪犯 cmodel 模型文件,包括 外形,大小,攻击范围image 游戏 level 关卡文件,包含单击任务的对话。角色的道具,hp,场地等各项设定 mmv 录像文件,包括开场动画,剧情动画。 music 游戏背景 pmodel 人物动作,人物模型 。 sn01 sn21 地 件 《如果增加...