import java.io.File;
import java.io.IOException;
public class FileSeparator {
public static void main(String[] args) {
try {
문자열 파일 이름 = "nouveau_fichier.txt";
문자열 currentdirectory= System.getProperty("user.dir");
문자열 absoluteFilePath = "";
absoluteFilePath = 현재 디렉토리 + File.separator + 파일 이름;
System.out.println("절대 경로: " + absoluteFilePath);
파일 파일 = 새 파일(absoluteFilePath);
if (file.createNewFile()) {
System.out.println("파일이 생성되었습니다!");
} else {
System.out.println("파일이 이미 존재합니다.");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
절대 경로: C:\Documents and Settings\Poste07\workspace\File\nouveau_fichier.txt
파일 생성됨!
import java.io.File;
import java.io.IOException;
public class NewFile {
public static void main(String[] args) {
try {
문자열 파일 이름 = "nouveau_fichier.txt";
현 현재 디렉토리 = System.getProperty("user.dir");
파일 파일 = 새 파일(현재 디렉토리, 파일 이름);
System.out.println("경로: " + file.getAbsolutePath());
if (file.createNewFile()) {
System.out.println("파일이 생성되었습니다!");
} else {
System.out.println("파일이 이미 존재합니다.");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
경로: C:\Documents and Settings\Poste07\workspace\File\nouveau_fichier.txt
파일이 이미 있습니다.
import java.io.File;출력:
import java.io.IOException;
public class NewFile {
public static void main(String[] args) {
try {
문자열 파일 이름 = "nouveau_fichier.txt";
현 현재 디렉토리 = System.getProperty("user.dir");
문자열 AbsolutePath = "";
문자열 os = System.getProperty("os.name").toLowerCase();
if (os.indexOf("win") >= 0) {
//if windows
Absolutepath = currentdirectory + "\\" + filename;
} else if (os.indexOf("nix") >= 0 ||
os.indexOf("nux") >= 0 ||
os.indexOf("mac") >= 0) {
//유닉스 또는 맥인 경우
AbsolutePath = currentDirectory + "/" + 파일 이름;
}else{
//OS를 찾을 수 없음
AbsolutePath = currentdirectory + "/" + filename;
}
System.out.println("경로: " + AbsolutePath);
파일 파일 = 새 파일(AbsolutePath);
if (file.createNewFile()) {
System.out.println("파일 생성됨");
} else {
System.out.println("파일이 이미 존재함");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
경로: C:\Documents and Settings\Poste07\workspace\File\nouveau_fichier.txt리소스:
파일이 이미 있습니다.
Please disable your ad blocker and refresh the window to use this website.