目前,我有这个:
String URL = "//Somewhere in my computer";
PrintWriter list = new PrintWriter(new FileWriter(URL, true));
是否可以写入包含文档的在线站点?例如,在某些网站中,您只需要将该网站的 URL 写入该文档即可。是否可以从 java 程序中读取和编辑此类内容?
这就是我为 TitanPad 服务所做的:
String someText = "Here goes magical text";
URL url = null;
try {
url = new URL("https://titanpad.com/3VBeN3Xo31");
} catch (MalformedURLException e) {
e.printStackTrace();
}
URLConnection connection = null;
try {
connection = url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
connection.setDoOutput(true);
OutputStream outStream = null;
try {
outStream = connection.getOutputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
outStream.write(someText.getBytes(Charset.forName("UTF-8")));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
outStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
最佳答案
您可以使用 FTP-
String someText = "Here goes magical text";
URL url = new URL("ftp://user:password@somewebsite.com/filename.txt");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStream outStream = connection.getOutputStream();
outStream.write(someText.getBytes(Charset.forName("UTF-8")));
outStream.close();
关于Java:在线保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33431798/