Java: 在线保存到文件
Java: Save to a file online
目前,我有这个:
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();
目前,我有这个:
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();