当前位置:编程学习 > JSP >>

jsp 目录 文件操作

jsp教程 目录 文件操作

file file1 = new file ("c:tempmynote.txt"); // in windows
file file2 = new file ("/tmp/mynote.txt"); // in linux/unix

检测文件路径

import java.io.file;
public class mainclass {
  public static void main(string[] a) {
    file myfile = new file("c:" + file.separator + "jdk1.5.0" +

file.separator, "file.java");
    system.out.println(myfile.getname());
    system.out.println(myfile.getpath());
  }
}

获取远程图片

import java.io.file;
import java.net.uri;

public class mainclass {
  public static void main(string[] a) throws exception {

    file remotefile = new file(new uri("file:///index.htm"));
  }
}

上级目录

 

import java.io.file;
public class mainclass {
  public static void main(string[] a) {
    file myfile = new file("c:" + file.separator + "jdk1.5.0" +

file.separator, "file.java");
    system.out.println(myfile.getparent());
    system.out.println(myfile);
  }
}

判断是否为目录

import java.io.file;
public class mainclass {
  public static void main(string[] a) {
    file myfile = new file("c:" + file.separator + "jdk1.5.0" +

file.separator, "file.java");
    system.out.println(myfile.isdirectory());
  }
}

是否为文件

import java.io.file;
public class mainclass {
  public static void main(string[] a) {
    file myfile = new file("c:" + file.separator + "jdk1.5.0" +

file.separator, "file.java");
    system.out.println(myfile.isfile());
  }
}

补充:Jsp教程,J2EE/EJB/服务器
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,