자바 코딩 질문
조회수 494회
안녕하세요 계산기 를 하나 만들었는데요 exit 입력하면 계산 값이 calculator.txt 에 저장되게하는것을 못하겠습니다 .. 밑에는 main.java 입니다
import java.io.*; public class main {
public String createFolder(String folderName) { String returnValue=""; String folderPath="C:\";
if(folderName==null) {
returnValue="폴더이름 입력";
}else {
folderPath += folderName;
File createFolder=new File(folderPath);
if(!createFolder.exists()) {
try {
createFolder.mkdir();
returnValue=folderName+"폴더 생성";
}catch(Exception e) {
returnValue = e.toString();
}
}else {
returnValue=folderName+"폴더 생성 있음";
}
} return returnValue;
}
public String createFile(String folderName,String fileName,String fileContents) { String returnValue=""; String folderPath="C:\";
if(folderName==null) {
returnValue="폴더이름 입력";
}else if(fileName ==null) {
returnValue="파일 이름 입력";
}else if(fileContents ==null){
returnValue="파일 내용 입력";
}else {
try {
folderPath += folderName;
File embeddedFoler=new File(folderPath);
if(embeddedFoler.exists()) {
String filePath = folderPath + "\\"+fileName;
File createFileName = new File(filePath);
if(!createFileName.isFile()) {
OutputStream createFile = new FileOutputStream(filePath);
byte[] byteString = fileContents.getBytes();
createFile.write(byteString);
createFile.close();
returnValue=fileName+"파일 생성 ";
}else {
returnValue=folderName+"폴더 존재";
}
}else {
returnValue=folderName+"폴더 ㄴㄴ 생성 다시 ㄱ";
}
}catch(Exception e) {
returnValue = e.toString();
}
} return returnValue;
}
public String readFile(String folderName,String fileName) { String returnValue=""; String folderPath="C:\";
if(folderName==null) {
returnValue="폴더이름 입력";
}else if(fileName ==null) {
returnValue="파일 이름 입력";
}else {
try {
folderPath += folderName;
File embeddedFoler=new File(folderPath);
if(embeddedFoler.exists()) {
String filePath = folderPath + "\\"+fileName;
File readFile = new File(filePath);
if(readFile.isFile()) {
FileReader fileReader = new FileReader(readFile);
int currentPoint=0;
while((currentPoint = fileReader.read())!= -1) {
returnValue +=(char)currentPoint;
}
fileReader.close();
}else {
returnValue=folderName+"폴더 존재";
}
}else {
returnValue=folderName+"폴더 ㄴㄴ ";
}
}catch(Exception e) {
returnValue = e.toString();
}
} return returnValue;
}
}
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력