导航:首页 > 编程语言 > java文件保存本地

java文件保存本地

发布时间:2022-04-26 14:52:17

‘壹’ 编写好的java程序如何导出保存并运行

首先,你需要在记事本中写一个“你好,下午好”的程序。

‘贰’ java 从数据库取数据并存入本地文本中

fos = new FileOutputStream(new File(dir, entry.getKey()+".txt"), true);

把FileOutputStream的第二个参数设置为true,就表示追加内容

‘叁’ java 从数据库取出数据并保存到本地文本中

先看数据库表, 我里面有46条记录,其中有三条重复,我就拿其中一条emp_id 为"

DWR65030M" 做例子

里面有两条记录 ,实现了

‘肆’ eclipse 里创建的java文件保存在哪里

比如上图所示的Demo.java ,首先进入当前 eclipse所在的 工作区,比如:d:workspace,后面是项目名称,然后根据包结构建立的路径:d:workspaceillmmsrccom estDemo.java

‘伍’ 如何用JAVA编程实现抓取某一页面的内容并保存成本地文件

import java.io.*;
import java.net.*;
public class server
{
public static void main(String[] args)
{
System.out.println("server starting.......");
try{
serversocket server=new serverSocker(7777);//listen7777port
Socket st=accpet();
BufferdReader br_net=new BufferdReader(new InputStreamReader)
BufferdReader br_key=new BufferdReader(new InputStreamReader)
printWriter pw=new PrintWriter(st.getOutputStream());
while(true){
String a=br_key.readLine();
pw.println(D:\);
pw.flush();

s=br_net.readLine();
system.out.println("hesays"+s);
}
}catch(Exception e){}

‘陆’ java里数据怎么保存到硬盘或TXT文件里去

Java通过使用I/O文件操作类,来创建输入输出流,将数据保存在file tet文件里面。示例如下:

importjava.io.File;importjava.io.FileOutputStream;importjava.io.IOException;publicclassWriteFileExample{publicstaticvoidmain(String[]args){FileOutputStreamfop=null;Filefile;Stringcontent="Thisisthetextcontent";try{file=newFile("c:/newfile.txt");fop=newFileOutputStream(file);//iffiledoesntexists,thencreateitif(!file.exists()){file.createNewFile();}//getthecontentinbytesbyte[]contentInBytes=content.getBytes();fop.write(contentInBytes);fop.flush();fop.close();System.out.println("Done");}catch(IOExceptione){e.printStackTrace();}finally{try{if(fop!=null){fop.close();}}catch(IOExceptione){e.printStackTrace();}}}}

‘柒’ 怎样将JAVA程序中接受的信息保存下来

1.保存到数据库,如果是要保存到本地,而不是服务器的话可以使用access数据库 2.通过io流保存到本地文件,当然可以使用加密

‘捌’ java如何保存文件

这是我原来做的例子,里面有文件储存的内容,代码不多,给你参考参考.
/**
* 五个按钮的故事,西西哈。
*/
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);
}
}
}

‘玖’ 如何把java项目文件夹放到自己的文件夹中

第一步:直接先创建一个java项目;
第二步:将文件夹复制到java项目本地存储路径相应的src文件夹下。
第三步:刷新eclipse中的java项目,即可完成”导入“操作,否则不是java项目的话,是没法导入的。

‘拾’ Java如何利用url下载MP3保存到本地

Java如何利用url下载MP3保存的方法:

1 /** ;

2 * TODO 下载文件到本地 ;

3 * @author nadim ;
4 * @date Sep 11, 2015 11:45:31 AM ;

5 * @param fileUrl 远程地址 ;

6 * @param fileLocal 本地路径 ;

7 * @throws Exception ;
8 */ ;

9 public void downloadFile(String fileUrl,String fileLocal) throws Exception {;

10 URL url = new URL(fileUrl);

11 HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();

12 urlCon.setConnectTimeout(6000);

13 urlCon.setReadTimeout(6000);

14 int code = urlCon.getResponseCode();

15 if (code != HttpURLConnection.HTTP_OK) {

16 throw new Exception("文件读取失败");

17 }

18 //读文件流;

19 DataInputStream in = new DataInputStream(urlCon.getInputStream());

20 DataOutputStream out = new DataOutputStream(new FileOutputStream(fileLocal));

21 byte[] buffer = new byte[2048];

22 int count = 0;

23 while ((count = in.read(buffer)) > 0) {;

24 out.write(buffer, 0, count);

25 }

26 out.close();

27 in.close();

28 }。

Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。

Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 。

阅读全文

与java文件保存本地相关的资料

热点内容
解压包如何转音频 浏览:447
机明自动编程软件源码 浏览:325
php端口号设置 浏览:540
phperegreplace 浏览:320
androidgridview翻页 浏览:537
ssh协议编程 浏览:634
如何开我的世界电脑服务器地址 浏览:861
玄关pdf 浏览:609
程序员学习论坛 浏览:940
程序员的毒鸡汤怎么做 浏览:548
安卓怎么降级软件到手机 浏览:281
云与服务器入门书籍推荐产品 浏览:636
delphi编程助手 浏览:762
电脑遇到服务器问题怎么办 浏览:515
加工中心编程结束方法 浏览:296
了解什么是web服务器 浏览:140
面向对象的编程的基本特征 浏览:718
php定时执行任务linux 浏览:787
php数组中删除元素 浏览:725
萤石云服务器视频 浏览:270