当前位置: 技术问答>java相关
在java如何获取当前运行的程序的路径?
来源: 互联网 发布时间:2015-07-22
本文导语: 在java如何获取当前运行的程序的路径?然后建立一个新的文件夹? 给个例子,谢先了! | import java.io.*; public class Test { public static void main(String[] args) { File directory = new File("."); try...
在java如何获取当前运行的程序的路径?然后建立一个新的文件夹?
给个例子,谢先了!
给个例子,谢先了!
|
import java.io.*;
public class Test {
public static void main(String[] args) {
File directory = new File(".");
try {
File newPath = new File(directory.getCanonicalPath()+"NewFolder");
newPath.mkdir();
}catch(Exception exp)
{
exp.printStackTrace();
}
}
}
//File directory = new File(".");
//directory.getCanonicalPath();取得当前路径
public class Test {
public static void main(String[] args) {
File directory = new File(".");
try {
File newPath = new File(directory.getCanonicalPath()+"NewFolder");
newPath.mkdir();
}catch(Exception exp)
{
exp.printStackTrace();
}
}
}
//File directory = new File(".");
//directory.getCanonicalPath();取得当前路径
|
import java.io.*;
public class Test {
public static void main(String[] args) {
File directory = new File(".");
try {
File newPath = new File(directory.getCanonicalPath()+"NewFolder");
newPath.mkdir();
}catch(Exception exp)
{
exp.printStackTrace();
}
}
}
//File directory = new File(".");
//directory.getCanonicalPath();取得当前路径
public class Test {
public static void main(String[] args) {
File directory = new File(".");
try {
File newPath = new File(directory.getCanonicalPath()+"NewFolder");
newPath.mkdir();
}catch(Exception exp)
{
exp.printStackTrace();
}
}
}
//File directory = new File(".");
//directory.getCanonicalPath();取得当前路径
|
代码如下:
public class Test {
public static void main(String[] args) {
System.out.println(System.getProperty("user.dir"));
createFolder("hello");
}
private static void createFolder(String folderName) {
String temp = System.getProperty("user.dir") + java.io.File.separator+ folderName;
java.io.File f = new java.io.File(temp);
f.mkdirs();
}
}
public class Test {
public static void main(String[] args) {
System.out.println(System.getProperty("user.dir"));
createFolder("hello");
}
private static void createFolder(String folderName) {
String temp = System.getProperty("user.dir") + java.io.File.separator+ folderName;
java.io.File f = new java.io.File(temp);
f.mkdirs();
}
}