我正在测试代码,其中我必须从用户输入输入,直到用户输入“停止”单词,我必须将其写入文件。我在代码中出现错误。没有合适的方法找到写(字符串)
代码:
import java.io.*;
import java.util.*;
public class fh1
{
public static void main(String args[])throws IOException
{
FileOutputStream fout = new FileOutputStream("a.log");
boolean status = true;
while (status)
{
System.out.println("Enter the word : ");
Scanner scan = new Scanner(System.in);
String word = scan.next();
System.out.println(word);
if (word.equals("stop"))
{
status = false;
}
else
{
fout.write(word);
}
}
fout.close();
}
}
我收到以下错误:
fh1.java:28: error: no suitable method found for write(String)
fout.write(word);
^
method FileOutputStream.write(byte[],int,int) is not applicable
(actual and formal argument lists differ in length)
method FileOutputStream.write(byte[]) is not applicable
(actual argument String cannot be converted to byte[] by method invocation conversion)
method FileOutputStream.write(int) is not applicable
(actual argument String cannot be converted to int by method invocation conversion) method FileOutputStream.write(int,boolean) is not applicable (actual and formal argument lists differ in length) 1 error
这个错误是什么意思,如何解决呢?