Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How to copy objects?

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic