동시에 모니터로 인쇄하는 동안 파일로 인쇄하려고합니다. 그건 그렇고, 그것은 모니터에 완벽하게 잘 인쇄합니다. 내 코드는 파일을 생성하지 않습니다. 그것은 내 코드의 다른 부분에 파일을 생성했기 때문에 매우 혼란 스럽습니다.파일과 모니터를 동시에 인쇄하는 방법은 무엇입니까?
나는 solution이 내 문제와 비슷하지만 FileOutputStream 또는 PrintStream에 대해 알지 못한다는 것을 알고 있습니다. 나는 코딩 수업에 대한 소개를하고 수업에서 배운 것을 사용할 수 있습니다. 이것을 이루기위한 다른 방법이 있습니까?
아래 코드는 제 코드입니다.
public static void printLine(char n, int count) throws IOException //prints lines of chord
{
FileWriter file = new FileWriter("outFile.txt",true);
PrintWriter outputfile = new PrintWriter(file);
//File outFile = new File("outFile.txt");
char[] lineNames = {'f','d','B','G','E','C'};
char[] spaceNames = {'e','c','A','F','D'};
char[] lineAr = {'-','-',n,'-','-'}; //array to print lines
char[] spaceAr = {' ',' ',n,' ',' '}; //array to print spaces
//print line
if(n == lineNames[count])
{
lineAr[2] = n;
}
else
lineAr[2] = '-';
for(int x = 0; x<5; x++)
{
System.out.print(lineAr[x]); //prints to monitor
outputfile.print(lineAr[x]); //prints to output file
}//end for loop
System.out.println();
//print space
if(n == spaceNames[count])
{
spaceAr[2] = n;
}
else
spaceAr[2] = ' ';
for(int x = 0; x<5; x++)
{
System.out.print(spaceAr[x]);
outputfile.print(lineAr[x]);
}//end for loop
System.out.println();
//print line C
if(n == 'C')
{
lineAr[2] = n;
}
else
lineAr[2] = '-';
for(int x = 0; x<5; x++)
{
System.out.print(lineAr[x]);
outputfile.print(lineAr[x]);
}//end for loop
System.out.println();
outputfile.close();
}//end printLine method
수동으로 파일을 만들려고했지만 해당 파일에 인쇄 할 코드가 있지만 파일이 비어 있습니다.
가능성을 [콘솔 및 텍스트 파일에 쓰기] (https://stackoverflow.com/questions/16237546/writing-to-console-and-text-file) – vinS
감사합니다. FileOutputStream에 대해 배웠고 클래스에서 배운 내용 만 사용할 수 있습니다. 이것을 이루기위한 다른 방법이 있습니까? @vinS –