내 Java 콘솔 출력을 내 데스크탑의 .txt 파일에 쓰려고합니다. 하지만 그 방법이 시작되면 콘솔 출력이 있고 txt 파일이 만들어 지지만 비어있어 BufferedReader (in)가 작동하지 않는다는 것을 깨달았습니다 ... ("ok1 - i"문으로 인해)콘솔 출력을 .txt 파일로 작성하십시오.
질문은 무엇입니까 ?? 또는 내 코드에 무엇이 잘못 되었습니까 ?? 당신이 볼과 당신의 시간을
package noobxd;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
public class Main {
public static void main(String[] args) throws IOException {
String path = "C:\\Users\\Mario\\Desktop\\output.txt";
generate_codes();
writetxt(path);
}
private static void writetxt(String path) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new FileWriter(path));
try {
String inputLine;
inputLine = "";
int i=0;
System.out.println("Starting");
while (!inputLine.isEmpty()){
System.out.println("ok1"+i);
inputLine = in.readLine();
System.out.println("ok2"+i);
out.write(inputLine);
System.out.println("ok3"+i);
out.newLine();
System.out.println("ok4"+i);
i++;
}
System.out.print("Write Successful");
} catch (IOException e1) {
System.out.println("Error during reading/writing");
} finally {
out.close();
in.close();
}
}
private static void generate_codes() {
Random rnd = new Random();
for (int i = 0; i < 30; i++) {
int code = rnd.nextInt(201) + 100;
int students = rnd.nextInt(31) + 40;
int j = rnd.nextInt(4);
String type = new String();
switch (j) {
case 0:
type = "Theory";
break;
case 1:
type = "Lab";
break;
case 2:
type = "Practice";
break;
case 3:
type = "Exam";
break;
}
System.out.println("TEL" + code + "-TopicNumber" + i + "-" + students + "-" + type);
}
}
}
감사를 실행할 수 있도록이, 내 코드입니다, 내 문제를 해결하는 데 도움이 바랍니다.
+1) –
롤 hahah @UncleIroh이 기반 내 자바-SQL에서 사용되는 나를 txt 파일을 내보낼 수 있도록하는 "별도의 응용 프로그램은"이기 때문이다 앱 (주 하나, txt 파일을 가져올 수 있습니다.) 그래서 그냥 콘솔에 다음 noobxd – Mgustavoxd1