我使用这段代码将数据保存到.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 我需要对代码片段做些什么才能完成保存?
答案 0 :(得分:1)
1-“域”在同一台服务器上管理,然后您只需将文件放在正确的位置(通常在“www”文件夹下,检查您的Web服务器配置)
2-这是另一台计算机,那么你必须在那里传输文件(FTP?使用套接字的另一个Java代码片段?主机提供的API?...)
不相关,但您应close
阻止Streams
finally
xxxxxxxStream s = null;
try {
s = new xxxxxxxStream();
} catch (WhateverException we) {
...
} finally {
s.close();
}