try
{
URL url = new URL("http://localhost:8080/Files/textfile.txt");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStream outStream = connection.getOutputStream();
ObjectOutputStream objectStream = new ObjectOutputStream(outStream);
objectStream.writeInt(637);
objectStream.writeObject("Hello there");
objectStream.writeObject(new Date());
objectStream.flush();
objectStream.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
i am unable to write text into the file(textfile.txt) . i dn't know wat the problem is?? can anyone explain how to write data to a text file based on url information ...
try { URL url = new URL(http://localhost:8080/Files/textfile.txt); URLConnection connection = url.openConnection(); connection.setDoOutput(true); OutputStream outStream
Share
Either you need to write to the file locally (after downloading it) and then upload it via FTP again. Or if it’s located on your server, you need to open it as a
Fileobject and then write/append to it with aBufferedWriterfor example.You need to use the absolute/relative path from your server’s point of view to locate the file in order to write to it!
EDIT: You can read more about remote file access in java HERE.