導航:首頁 > 編程語言 > 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文件保存本地相關的資料

熱點內容
銀河麒麟字體庫存在哪個文件夾 瀏覽:956
魔獸加丁伺服器的航空叫什麼 瀏覽:152
花冠改裝案例哪個app多 瀏覽:515
成績單app哪個好用 瀏覽:140
北美程序員vs國內程序員 瀏覽:181
php解析xml文檔 瀏覽:121
石墨文檔APP怎麼橫屏 瀏覽:185
牆主鋼筋加密和非加密怎麼看 瀏覽:144
金山區文件夾封套定製 瀏覽:708
soho程序員 瀏覽:672
java位元組截取 瀏覽:525
php提交作業 瀏覽:815
房產還沒解壓可以辦理贈予嗎 瀏覽:224
java毫秒轉分鍾 瀏覽:753
模式識別中文pdf 瀏覽:774
c語言平均數字編譯錯誤 瀏覽:171
單片機算交流 瀏覽:45
php自適應網站 瀏覽:467
2b2t伺服器怎麼獲得許可權 瀏覽:816
c語言javaphp 瀏覽:804