gpt4 book ai didi

java - 将数据保存到托管 .dat 文件

转载 作者:行者123 更新时间:2023-12-01 15:14:14 25 4
gpt4 key购买 nike

我使用这段代码将数据保存到 .dat 文件中:

void saveFile () {

try {
FileOutputStream fos = new FileOutputStream ("File.dat", true);
DataOutputStream dos = new DataOutputStream (fos);
dos.writeUTF (saves[count][0]);
dos.writeUTF (saves[count][1]);
dos.writeUTF (saves[count][2]);
dos.writeUTF (saves[count][3]);
dos.writeUTF (saves[count][4]);
dos.writeUTF (saves[count][5]);
JOptionPane.showMessageDialog (this, "The Record has been Saved Successfully",
"Record Saved", JOptionPane.PLAIN_MESSAGE);
txtClear ();
dos.close();
fos.close();
}
catch (IOException ioe) {
JOptionPane.showMessageDialog (this, "There are Some Problem with File",
"Problem", JOptionPane.PLAIN_MESSAGE);
}

}

我需要将 .dat 文件托管在某个在线域上,比如 http://Domain.com/File.dat我需要对这段代码做什么才能完成保存?

最佳答案

1-“域”在同一服务器上管理,然后您只需将文件放在正确的位置(通常在“www”文件夹下,检查您的网络服务器配置)

2-这是另一台计算机,那么您必须将文件传输到那里(FTP?另一段使用套接字的Java代码?主机提供的API?...)

<小时/>

不相关,但您应该在finally block 中关闭您的Streams

xxxxxxxStream s = null;
try {
s = new xxxxxxxStream();
} catch (WhateverException we) {
...
} finally {
s.close();
}

关于java - 将数据保存到托管 .dat 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11865180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com