• 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Writing files on remote server

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have follwoing Java program. Seems it does work but does not copy any file. This should copy from my hard drive to a URL. Any idea?

import java.io.*;
import java.net.*;


public class loadimage {

public static void main(String[] args) {

try
{
URL u = new URL("http://localhost:9050/jsp-examples";);
URLConnection uc = u.openConnection();

// uc.connect();
uc.setDoOutput(true);

OutputStream fout = uc.getOutputStream();



FileInputStream fin = new FileInputStream("c:/xxx");

System.out.println("aaa");

byte[] buffer = new byte[256];
while(true)

{

int bytesRead = fin.read(buffer);
System.out.println(bytesRead);
if (bytesRead == -1) break;
fout.write(buffer, 0, bytesRead);
System.out.println("qaaa");

}

fin.close();
fout.close();
}

catch (IOException ioe) {System.err.println(ioe.toString()); }

}
}
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic