为什么赢了';BufferedWriter实例化是否在Java中写入txt文件?
我试图用BufferedWriter实例化一个对象,但它不起作用。问题发生在我使用write函数时。为什么它不让我写入文件? 错误是找不到符号。请帮帮我。我知道有人知道。当这是bufferedWriter方法时,为什么找不到符号为什么赢了';BufferedWriter实例化是否在Java中写入txt文件?,java,bufferedwriter,writer,Java,Bufferedwriter,Writer,我试图用BufferedWriter实例化一个对象,但它不起作用。问题发生在我使用write函数时。为什么它不让我写入文件? 错误是找不到符号。请帮帮我。我知道有人知道。当这是bufferedWriter方法时,为什么找不到符号 package ex5_abcd; import java.nio.file.*; import java.io.*; import static java.nio.file.StandardOpenOption.*; import java.util.Scanner
package ex5_abcd;
import java.nio.file.*;
import java.io.*;
import static java.nio.file.StandardOpenOption.*;
import java.util.Scanner;
public class EX5_ABCD {
public static void main(String[] args) {
boolean go = true;
String firstN, lastN;
String lineWritten = "";
int IdNum;
Scanner input = new Scanner(System.in);
Path file = Paths.get("C:\\Java\\empList.txt");
try {
OutputStream output = new BufferedOutputStream(Files.newOutputStream(file, CREATE));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
while (go) {
System.out.println("Please enter Employee's First Name");
firstN = input.nextLine();
System.out.println("Please enter Employee's Last Name");
lastN = input.nextLine();
System.out.println("Please enter " + firstN + " " + lastN);
IdNum = input.nextInt();
lineWritten = IdNum + " " + firstN + " " + lastN;
int lineLength = lineWritten.length();
char [] testChar = new char[1];
testChar [0] = 'a';
writer = write(testChar, 0, lineLength); // Why write error
writer.flush();
writer.newLine();
}
writer.close();
} catch (Exception e) {
System.out.println("Error Msg:" + e);
}
}
}
应该改写为
writer.write(lineWritten, 0, lineLength);
由于writer
不是对对象的引用,因此应该调用writer对象的方法,而不是将writer
设置为另一个值
概述:
(=)设置一个值
此外,由于在循环中从未将
go
的值设置为false,因此将继续在那里循环。。。永远。。。而且。。。。我建议不要让这种情况发生取消对同花顺的注释?仍然不起作用,兄弟,重复的Sotirios Delimanolis在哪里。我想看看,先生。@SotiriosDelimanolis我们能解开这个,因为它不是一个真正的骗局吗?我想它也不是骗局。@JClassic我建议你不要回答这样的问题。它们应该以拼写错误的形式关闭,或者因为这一问题的解决方式不太可能帮助未来的读者。或作为具有给定规范答案的重复项关闭。我知道你现在没有这个名声,但当你这么做的时候,那就是你应该做的。
writer.write(lineWritten, 0, lineLength);