怎么从一个文件中内容写入到另一个文件
用fileoutputstream输出和fileinputstram输入
把一个文件中内容写入到另一个文件中哦,我现在刚学这个输入输出问题多多
我要完成的是要从textarea输入的内容用fileoutputstream输出保存到一个文件中
遇到了数据类型转化问题,
就想到先用randomaccessfile中的writechars(string)写到一个文件中
再把这个文件用fileinputstrwam输入程序又遇到了问题哦,想每次读取怎么知道已经读到文件结尾,
fileoutputstream的写入函数又是write(byte[])或者是write(int b);类型的
自己也糊涂了
希望朋友给个程序,完整的给我看看就好了(用用fileoutputstream输出和fileinputstram输入)
------解决方案--------------------忍痛割爱,把我今天刚完成的记事本程序给你得了,功能还不是很完善,但毕竟可以打开文件(读)和保存文件(写),我用的JDK是1.6的,程序代码如下:
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import javax.swing.*;
import java.io.*;
public class TextEdit extends Frame implements ActionListener
{
static TextEdit frame = new TextEdit();
static MenuBar mb = new MenuBar();
static Menu menu1 = new Menu( "File ");
static Menu menu2 = new Menu( "Edit ");
static Menu menu3 = new Menu( "Format ");
static Menu menu4 = new Menu( "Help ");
static MenuItem item1 = new MenuItem( "New ");
static MenuItem item2 = new MenuItem( "Open ");
static MenuItem item3 = new MenuItem( "Save As ");
static MenuItem item4 = new MenuItem( "Exit ");
static MenuItem item5 = new MenuItem( "Cut ");
static MenuItem item6 = new MenuItem( "Copy ");
static MenuItem item7 = new MenuItem( "Paste ");
static MenuItem item8 = new MenuItem( "Font ");
static MenuItem item9 = new MenuItem( "About TextEdit 1.0 ");
static MenuItem item10 = new MenuItem( "Color ");
static Dialog fontDialog = new Dialog(frame, "FontDialog ", false);
static List fontList = new List(7, false);
static List sizeList = new List(7, false);
//获取系统字体
static Font[] font = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
static int[] size = new int[23];
static Button okButton = new Button( "OK ");
static Button cancelButton = new Button( "Cancel ");
static Label label1 = new Label( "Font ", Label.CENTER);
static Label label2 = new Label( "Size ", Label.CENTER);
static ColorChooser chooser = new ColorChooser();
static TextArea textarea = new TextArea();
static FileDialog openfile;
static FileDialog savefile;
static Clipboard clipboard = frame.getToolkit().getSystemClipboard();
public static void main(String[] args)throws
IOException {
menu1.add(item1);
menu1.add(item2);
menu1.add(item3);
menu1.add(item4);
menu2.add(item5);
menu2.add(item6);
menu2.add(item7);
menu3.add(item8);
menu3.add(item10);
menu4.add(item9);
mb.add(menu1);
mb.add(menu2);
mb.add(menu3);
mb.add(menu4);
fontDialog.setLayout(null);
fontDialog.setBounds(80, 80, 300, 350);
fontDialog.setResizable(false);
fontDialog.add(fontList);
fontDialog.add(sizeList);
fontDialog.add(okButton);
fontDialog.add(cancelButton);
fontDialog.add(label1);
fontDialog.add(label2);
fontDialog.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
fontDialog.dispose();
}
});
fontList.setBounds(10, 70, 200, 200);
sizeList.setBounds(230, 70, 50, 200);
fontList.select(129);
sizeList.select(5);
okButton.setBounds(30, 290, 60, 20);
cancelButton.setBounds(180, 290, 60, 20);
label1.setBounds(10, 50, 200, 20);
label1.setBackground(new Color(121, 121, 121));
label2.setBounds(230, 50, 50, 20);