• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to copy objects?

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Suppose that i have a java file say 'myObject.java' at a particular url. Now i want to copy that java file to C:\
Which is the easiest means to achieving this?
..Regards
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi joseph,
Here is the sample code to achieve your task.
/* fileWriteMethod.java */
import java.net.*;
import java.io.*;
import java.util.*;
class fileWriteMethod
{
public static void main(String ar[])
throws IOException
{

URL url=new URL("http://www.joseph.com/myObject.java");
BufferedReader buf=new BufferedReader(new InputStreamReader(url.openStream()));
String in="";
StringBuffer strbuffer=new StringBuffer();
String temp="";


while ((in = buf.readLine()) != null)
{
if(in.length()>0)
strbuffer=strbuffer.append(in);

}

temp=strbuffer.toString();

byte[] b=temp.getBytes();
try
{
FileOutputStream file=new FileOutputStream("c:/file.txt");
file.write(b);
file.close();
}
catch(Exception e)
{
System.out.println("Error :"+e);
}
buf.close();
}
}

The above program reads the file myObject.java from the url and stores in the file "file.txt" in C drive..
Hope i fulfilled your request..
Best Regards,
Paramaguru
 
You can't have everything. Where would you put it?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic