📄 untitled1.java~51~
字号:
package stream;/** * Title: * Description: * Copyright: Copyright (c) 2002 * Company: * @author * @version 1.0 */import java.io.*;public class Untitled1{int c;boolean start=true; static RandomAccessFile in_and_out=null;static File path=new File("c:\\D");public static void main(String args[]) { try {in_and_out=new RandomAccessFile("tom.txt","rw");} catch(FileNotFoundException e) {System.out.println("PPPP?????"); } root(path ,5); } //编写二级以上目录和文件的递归遍历方法 public void tree(File a,int b) { File array[]; if(a.isDirectory()) {array=a.listFiles(); int d=b+5; for(int k=0;k<array.length;k++) { if(k==array.length-1) {if(start) {locate(c); try {in_and_out.writeBytes("|"); } catch(IOException e) {System.out.println("????????"); } locate(b-c); try {in_and_out.writeBytes("\\--"); } catch(IOException e) {System.out.println("????????"); } } else {locate(b); try {in_and_out.writeBytes("\\--"); } catch(IOException e) {System.out.println("????????"); } } } else {if(start) {locate(c); try {in_and_out.writeBytes("|"); } catch(IOException e) {System.out.println("????????"); } locate(b-c); try {in_and_out.writeBytes("+--"); } catch(IOException e) {System.out.println("????????"); } } else {locate(b); try {in_and_out.writeBytes("+--"); } catch(IOException e) {System.out.println("????????");} } } tree(array[k],d); } } else try {in_and_out.writeBytes(a.getName()+"\n");} catch(IOException e) {System.out.println("????????");} }//编写一级子目录和文件遍历方法 public void root(File classpath,int d ) {int i=0; locate(d); try {in_and_out.writeBytes(classpath.getAbsolutePath()+"\n"); // in_and_out.writeBytes(classpath.getName()); } catch(IOException e) {System.out.println("????????"); } d=d+classpath.toString().length()-2; c=d; File file[]; if(classpath.isDirectory()) {file=classpath.listFiles(); for(i=0;i<file.length;i++) { if(i==file.length-1) { locate(c); if(file[i].isDirectory()) { try {in_and_out.writeBytes("\\--"+file[i].getName()+"\n"); } catch(IOException e) {System.out.println("????????"); } start=false; } else { try {in_and_out.writeBytes("\\--"+file[i].getName()+"\n"); } catch(IOException e) {System.out.println("????????"); } start=false; continue; } } else { locate(c); if(file[i].isDirectory()) { try {in_and_out.writeBytes("+--"+file[i].getName()+"\n"); } catch(IOException e) {System.out.println("????????"); } } else { try {in_and_out.writeBytes("+--"+file[i].getName()+"\n"); } catch(IOException e) {System.out.println("????????"); } continue; } } } tree(file[i],c+5); } } //编写定位方法 public void locate(int b) {String s; char a[]=new char[100]; for(int i=0;i<b;i++) {a[i]=' '; } s=new String(a,0,b-1); try {in_and_out.writeBytes(s); } catch(IOException e) {System.out.println("????????"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -