import java.io.*; import java.awt.*;public class Save { public static void main(String[] args) throws IOException { TextArea ta=new TextArea("this is \n a text"); FileOutputStream f =new FileOutputStream("test.txt"); f.write(ta.getText().getBytes()); } }
不行 TextArea中的数据还是没读出来 出错了 cannot resolve symbol symbol : method write (java.lang.String) location: class java.io.File outputFile.write(output.getText()); ^
import java.awt.*; import java.awt.event.*; import java.io.*;public class Test extends Frame{ private TextArea t = new TextArea();
import java.awt.*;public class Save
{
public static void main(String[] args)
throws IOException
{
TextArea ta=new TextArea("this is \n a text");
FileOutputStream f =new FileOutputStream("test.txt");
f.write(ta.getText().getBytes());
}
}
TextArea中的数据还是没读出来
出错了
cannot resolve symbol
symbol : method write (java.lang.String)
location: class java.io.File
outputFile.write(output.getText());
^
import java.awt.event.*;
import java.io.*;public class Test extends Frame{
private TextArea t = new TextArea();
public Test(){
Button b = new Button("Save");
add("Center",t);
add("South",b);
pack();
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try{
FileOutputStream fos =new FileOutputStream("test.txt");
fos.write(t.getText().getBytes());
}catch(IOException ie){
ie.printStackTrace();
}
}
});
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
}
public static void main(String args[]){
new Test().show();
}
}如果t.getText()没有得到值 就先t.selectAll()然后在t.getText()
void cannot be dereferenced
out.write(output.selectAll().getText().getBytes());
^