操作系统课程设计 为LINUX 设计一个简单的二级文件系统 java实现界面

2026/4/25 7:24:11

MutableTreeNode node = (MutableTreeNode) path .getLastPathComponent();

DefaultTreeModel model = (DefaultTreeModel) tree.getModel();

if (node.getAllowsChildren()) {

String Name = JOptionPane.showInputDialog(null, \创建目录名称:\);

if (!Name.equals(\)) {

MutableTreeNode newNode = new

DefaultMutableTreeNode(Name);// 建立新节点

1);

+ Name);

tree.fireTreeExpanded(path);

model.insertNodeInto(newNode, node, 0); String fullPath = \;

for (Object obj : path.getPath()) { String str = obj.toString(); if (str.endsWith(\))

str = str.substring(0, str.length() -

if (fullPath.equals(\)) fullPath += str; else

fullPath += \ + str; }

File parentDir = new File(fullPath); if (parentDir.isDirectory()) { File currentFile = new File(fullPath + \ currentFile.mkdir(); }

} else {

JOptionPane.showMessageDialog(null, \目录名不

能为空\);

} else {

}

11

JOptionPane.showMessageDialog(null, \不能给文件

追加下级目录!\); return;

} } }

新建目录如图8所示,

图8 新建目录

3.4新建文件实现

新建文件主要代码:

private class NewFileAction implements ActionListener { public void actionPerformed(ActionEvent e) {

12

TreePath path = tree.getSelectionPath(); MutableTreeNode node = (MutableTreeNode) path .getLastPathComponent(); if (node.getAllowsChildren()) {

String fullPath = \;

for (Object obj : path.getPath()) { String str = obj.toString(); if (str.endsWith(\))

str = str.substring(0, str.length() - 1); if (fullPath.equals(\)) fullPath += str; else

fullPath += \ + str; }

String FileName =

JOptionPane.showInputDialog(null, \创建文件名称:\);

if (!FileName.equals(null)) { File f = new File(fullPath + \ + FileName); try {

f.createNewFile();

} catch (IOException e1) { e1.printStackTrace(); } } else {

JOptionPane.showMessageDialog(null, \不能添加

文件!\); return;

} } } }

13

新建文件如图9所示,

图9 新建文件

3.5删除文件实现

删除文件主要代码:

private class DeleteAction implements ActionListener{

public void actionPerformed(ActionEvent e) { TreePath tp = tree.getSelectionPath(); DefaultMutableTreeNode node =

(DefaultMutableTreeNode) tp.getLastPathComponent();

DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel();

14


操作系统课程设计 为LINUX 设计一个简单的二级文件系统 java实现界面.doc 将本文的Word文档下载到电脑
搜索更多关于: 操作系统课程设计 为LINUX 设计一个简单的二级文件系统 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219