我使用这段代码将数据保存到 .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/