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

📄 fileoperation.java

📁 手机资源管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		if (fileList != null) {
			fileList.removeAll();
			fileList.removeLeftCommand();
			new Thread(new Runnable() {
				public void run() {
					char[] buffer = new char[1024];
					int used = 0;
					int b = 0;
					String originalURL = fc.getURL();
					StringBuffer sb = new StringBuffer();
					String text;
					try {
						fc.setFileConnection(s);
						InputStream fin = fc.openInputStream();
						InputStreamReader rin = new InputStreamReader(fin);
						while (b != -1) {
							b = rin.read(buffer, 0, buffer.length);
							if (b != -1) {
								sb.append(buffer, 0, buffer.length);
								used = used + b;
							}

						}
						text = sb.toString();
						rin.close();
						fin.close();
						fileList.append(text, null);
						fileList.setTitle(s);

						((Row) (fileList.rows.elementAt(0))).ifCommand = false;
						fc = (FileConnection) Connector.open(originalURL);
						status = STATUS_TEXT;
						Lfm.lscreen.repaint();
					} catch (IOException e) {
						System.out.println("read text error!");
						e.printStackTrace();
					}
				}
			}).start();

		} else {
			return;
		}
	}

	private void back() {
		new Thread(new Runnable() {
			public void run() {
				try {
					if (fc != null) {

						fc.setFileConnection("..");

						showCurrentDir();

					}

				} catch (IOException e) {
					System.out.println("error in back to parent directory!");
					e.printStackTrace();
				}
			}
		}).start();
	}

	private boolean isDirectory(String s) {
		if (s.endsWith("/"))
			return true;
		else
			return false;
	}

	private void enterDirectory(final String s) {
		new Thread(new Runnable() {
			public void run() {
				try {
					if (fc != null) {
						fc.setFileConnection(s);
					} else {
						return;
					}
				} catch (Exception e) {
					System.out.println("enterDirectory error: " + s);
					e.printStackTrace();
				}
			}
		}).start();

	}

	private void delete(final String s) {
		new Thread(new Runnable() {
			public void run() {
				try {
					String originalURL = fc.getURL();
					fc.setFileConnection(s);
					fc.delete();
					fc = (FileConnection) Connector.open(originalURL);
					showCurrentDir();
				} catch (IOException e) {
					System.out.println("delete file or folder error!");
					e.printStackTrace();
				}
			}
		}).start();

	}

	private void showProperty(String s) {
		String originalURL = fc.getURL();

		try {
			fc.setFileConnection(s);
			currentFileURL = fc.getURL();
		} catch (IOException e) {
			System.out.println("show properties error!");
			e.printStackTrace();
		}

		propertyList = new List();
		propertyList.append("file's path: ");
		propertyList.append("" + fc.getURL());
		propertyList.append("     ");
		att = new ChoiceGroup(ChoiceGroup.MULTIPLE_CHOICE);

		att.append("read only");
		att.append("hidden");
		att.setSelectedIndex(0, !fc.canWrite());
		att.setSelectedIndex(1, fc.isHidden());

		propertyList.add(att);

		propertyList.append("lastModified");
		propertyList.append(String.valueOf(fc.lastModified()));
		propertyList.append("used space: ");
		propertyList.append("" + fc.usedSize());
		propertyList.append("available space: ");
		propertyList.append("" + fc.availableSize());
		propertyList.addLeftCommand(cmd_apply);
		propertyList.addRightCommand(cmd_back);
		propertyList.setCommandListener(this);
		try {
			fc = (FileConnection) Connector.open(originalURL);
		} catch (IOException e) {
			e.printStackTrace();
		}
		status = STATUS_PROPERTY;
		Lfm.lscreen.setCurrentPanel(propertyList);
	}

	private void applyFileAttributes() {
		if (att != null) {
			try {
				if (currentFileURL == null) {
					return;
				}
				String originalURL = fc.getURL();
				fc = (FileConnection) Connector.open(currentFileURL);
				fc.setWritable(att.ifSelected(0));
				fc.setHidden(att.ifSelected(1));
				fc = (FileConnection) Connector.open(originalURL);
			} catch (IOException e) {
				e.printStackTrace();
			}

		} else {
			return;
		}

		status = STATUS_FILE;
		Lfm.lscreen.setCurrentPanel(fileList);
	}

	private void copy(String s) {
		if (s != null) {
			copyorcutFileURL = fc.getURL() + s;
			copyorcutFilename = s;
			isCopied = true;
		} else {
			Lfm.lscreen.showAlert(null, "copy file can't be null");
		}

	}

	private void cut(String s) {
		if (s != null) {
			copyorcutFileURL = fc.getURL() + s;
			copyorcutFilename = s;
			isCut = true;
		} else {
			Lfm.lscreen.showAlert(null, "cut file can't be null");
		}

	}

	private void paste(final String s) {
		new Thread(new Runnable() {
			public void run() {
				try {
					String destination = fc.getURL() + s;

					if (isDuplicateInCurrentDir(s)) {
						destination = fc.getURL() + "copy of " + s;
					}

					FileConnection fin = (FileConnection) Connector
							.open(copyorcutFileURL);
					System.out.println("copyorcutFileURL: " + copyorcutFileURL);
					System.out.println("destination: " + destination);
					FileConnection fout = (FileConnection) Connector
							.open(destination);
					fout.create();
					InputStream in = fin.openInputStream();
					OutputStream out = fout.openOutputStream();
					int b = in.read();
					while (b != -1) {
						out.write(b);
						b = in.read();
					}
					in.close();
					out.close();
					if (isCut)
						fin.delete();
					fin.close();
					fout.close();
					isCopied = false;
					isCut = false;
					showCurrentDir();
				} catch (Exception e) {
					System.out.println("paste file error");
					e.printStackTrace();
				}
			}
		}).start();

	}

	private boolean isDuplicateInCurrentDir(String s) {
		if (fileList == null)
			return false;
		for (int i = 0; i < fileList.size(); i++) {
			String temp = fileList.getString(i);
			if (s.equals(temp))
				return true;
		}
		return false;
	}

	public void rename(final String s) {
		new Thread(new Runnable() {
			public void run() {
				try {
					String originalURL = fc.getURL();
					fc.setFileConnection(fileList.getSelectedString());
					// System.out.println(fc.getURL());
					fc.rename(s);
					fc = (FileConnection) Connector.open(originalURL);
					showCurrentDir();
				} catch (IOException e) {
					System.out.println("rename error!");
					e.printStackTrace();
				}
			}
		}).start();

	}

	public void commandAction(Command cmd, Displayable dis) {
		if (dis == inputBox) {
			if (cmd == cmd_ok) {
				String name = inputBox.getTitle();
				String text = inputBox.getString();
				makeFile(name, text, false, false);
				Lfm.display.setCurrent(Lfm.lscreen);
				Lfm.lscreen.setCurrentPanel(fileList);
				Lfm.lscreen.setFullScreenMode(true);
			} else if (cmd == cmd_cancel) {
				Lfm.display.setCurrent(form);
			}
		}
	}

	public void commandAction(Command cmd, Component cp) {
		if (status == STATUS_ROOT) {
			if (status == STATUS_ROOT) {
				if (cmd == cmd_quit) {
					lfm.quitApp();
				} else if (cmd == cmd_cancel) {
					firstPanel.closePopup(LUIConfig.LEFT);
				} else if (cmd == cmd_enter) {

					initialShortcuts();
					Lfm.lscreen.setCurrentPanel(fileList);
					showCurrentDir();
					Lfm.lscreen.repaint();
					status = STATUS_FILE;

				}
			} else {

			}
		} else if (status == STATUS_FILE) {
			if (cmd == cmd_enter) {
				String selectedString = fileList.getSelectedString();
				enter(selectedString);

			} else if (cmd == cmd_back) {
				back();
			} else if (cmd == cmd_delete) {
				String selectedString = fileList.getSelectedString();
				delete(selectedString);
			} else if (cmd == cmd_property) {
				showProperty(fileList.getSelectedString());
			} else if (cmd == cmd_copy) {
				copy(fileList.getSelectedString());
			} else if (cmd == cmd_cut) {
				cut(fileList.getSelectedString());
			} else if (cmd == cmd_paste) {
				if (copyorcutFilename != null) {
					paste(copyorcutFilename);
				}

			} else if (cmd == cmd_rename) {
				initialRename();
				Lfm.display.setCurrent(form);
			} else if (cmd == cmd_newFolder) {
				initialNewFolder();
				Lfm.display.setCurrent(form);
			} else if (cmd == cmd_newFile) {
				initialNewFile();
				Lfm.display.setCurrent(form);
			}
		} else if (status == STATUS_TEXT) {
			if (cmd == cmd_back) {
				showCurrentDir();
				fileList.addLeftCommand(cmd_enter);
				status = STATUS_FILE;
			}
		}else if (status == STATUS_IMAGE) {
			if (cmd == cmd_back) {
				
				fileList.addLeftCommand(cmd_enter);
				fileList.addRightCommand(cmd_back);
				status = STATUS_FILE;
				showCurrentDir();
				Lfm.lscreen.setCurrentPanel(fileList);
			}
		} else if (status == STATUS_PROPERTY) {
			if (cmd == cmd_back) {
				showCurrentDir();
				status = STATUS_FILE;
				Lfm.lscreen.setCurrentPanel(fileList);
			} else if (cmd == cmd_apply) {
				status = STATUS_FILE;
				applyFileAttributes();
			}
		}

	}

	public void commandAction(Command cmd, Item item) {
		if (item == renameField) {
			if (cmd == cmd_ok) {
				String newName = renameField.getString();
				rename(newName);
				Lfm.display.setCurrent(Lfm.lscreen);
				Lfm.lscreen.setCurrentPanel(fileList);
				Lfm.lscreen.setFullScreenMode(true);
			} else if (cmd == cmd_cancel) {
				Lfm.display.setCurrent(Lfm.lscreen);
				Lfm.lscreen.setCurrentPanel(fileList);
				Lfm.lscreen.setFullScreenMode(true);
			}
		} else if (item == newFolderField) {
			if (cmd == cmd_ok) {
				String folderName = newFolderField.getString();
				createNewFolder(folderName, false, false);
				Lfm.display.setCurrent(Lfm.lscreen);
				Lfm.lscreen.setCurrentPanel(fileList);
				Lfm.lscreen.setFullScreenMode(true);
			} else if (cmd == cmd_cancel) {
				Lfm.display.setCurrent(Lfm.lscreen);
				Lfm.lscreen.setCurrentPanel(fileList);
				Lfm.lscreen.setFullScreenMode(true);
			}
		} else if (item == newFileField) {
			if (cmd == cmd_ok) {
				String fileName = newFileField.getString();
				initialInputBox(fileName);
				Lfm.display.setCurrent(inputBox);
			} else if (cmd == cmd_cancel) {
				Lfm.display.setCurrent(Lfm.lscreen);
				Lfm.lscreen.setCurrentPanel(fileList);
				Lfm.lscreen.setFullScreenMode(true);
			}
		}
	}
}

⌨️ 快捷键说明

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