java中包可以保存工程需要的各种文件

Python031

java中包可以保存工程需要的各种文件,第1张

是的

输入文件内容和文件名称,将文件保存即可。

Java是一门面向对象编程语言,1990年代初由詹姆斯·高斯林等人开发出Java语言的雏形,最初被命名为Oak,后随着互联网的发展,经过对Oak的改造,1995年5月Java正式发布。

Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等。

2009年,甲骨文公司宣布收购Sun。2010年,Java编程语言的共同创始人之一詹姆斯·高斯林从Oracle公司辞职。2011年,甲骨文公司举行了全球性的活动,以庆祝Java7的推出,随后Java7正式发布。2014年,甲骨文公司发布了Java8正式版。

这是我原来做的例子,里面有文件储存的内容,代码不多,给你参考参考.

/**

* 五个按钮的故事,西西哈。

*/

import java.awt.*

import java.awt.event.*

import java.io.*

public class FileMessage extends Frame implements ActionListener

{

private static final long serialVersionUID = 10L

Dialog dia

private Panel p

private File fi

Process po=null

private String s

private TextArea ta

private FileDialog fd

private Button b1,b2,b3,b4,b5

private Button b6

public FileMessage()

{

super("文本文件处理")

setBackground( Color.LIGHT_GRAY )

setLocation(200,300)

setResizable( false)

setVisible( true)

addWindowListener( new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit( 0)

}

})

}

public void init()

{

ta=new TextArea("\n\n\n\n\n\t\t\t\t文本显示区")

ta.setSize(30,5)

ta.setEditable(false)

add( ta,"North")

p=new Panel()

add( p,"Center")

b1=new Button("浏览")

b2=new Button("保存")

b3=new Button("清空")

b4=new Button("关闭")

b5=new Button("独立打开")

b6=new Button("确定")

p.add(b1)

p.add(b2)

p.add(b3)

p.add(b4)

p.add(b5)

b1.addActionListener(this)

b2.addActionListener(this)

b3.addActionListener(this)

b4.addActionListener(this)

b5.addActionListener(this)

b6.addActionListener(this)

fd=new FileDialog(this,"请选择文件",FileDialog.LOAD)

fd.setDirectory("f:\\note")

pack()

dia=new Dialog(this,"注意",true)

dia.setLayout(new BorderLayout())

Panel p1=new Panel()

p1.add( b6)

dia.add(new Label(" 请先选择文件"),BorderLayout.CENTER)

dia.add( p1,BorderLayout.SOUTH)

dia.addWindowListener( new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

dia.setVisible( false)

}

})

dia.setLocation(310,370)

dia.setSize(200,130)

}

public static void main(String[] args)

{

new FileMessage().init()

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==b1)

{

fd.setVisible(true)

s=fd.getDirectory()+fd.getFile()

fi=new File(s)

byte[] b=new byte[(int)fi.length()]

try

{

new FileInputStream(fi).read(b)

ta.setText(new String(b,0,(int)fi.length()))

}

catch(Exception e1){}

ta.setEditable(true)

}

else if(e.getSource()==b2)

{

try

{

if(ta.getText().equals("保存成功")||ta.getText() .equals( ""))

{}

else

{

new FileOutputStream(fi).write(ta.getText().getBytes())

ta.setText("保存成功")

ta.setEditable(false)

}

}

catch(FileNotFoundException e1)

{

ta.setText(e1.getMessage())

}

catch(IOException e1)

{

ta.setText("出现IOException异常")

}

}

else if(e.getSource()==b4)

System.exit(0)

else if(e.getSource()==b3)

{

ta.setText("")

ta.setEditable( false)

}

else if(e.getSource()==b5)

{

if(s==null)

{

dia.setVisible(true)

}

else

{

try

{

po=Runtime.getRuntime().exec("notepad.exe "+s)

}

catch(Exception ei)

{}

}

}

else if(e.getSource() ==b6)

{

dia.setVisible(false)

}

}

}