Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

com.oreilly.servlet question

Posted on 2001-06-22
6
Medium Priority
?
226 Views
Last Modified: 2010-04-16
Hi everybody!

I am using the package com.oreilly.servlet for uploading files to my server.

What I wanted to do is upload an image that has a name but I want to save it in my server with another name.

I want to save the image:

client:  c:/images/image.jpg

and overwrite this image in the server in

server: c:/server/images/serverimage.jpg

is there any easy way to do it?

Thanks!

Pablo
0
Comment
Question by:pablete
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 3

Expert Comment

by:jerelw
ID: 6219483
1. create your File with the name you want
2. get your InputStream
3. write the stream to the File

0
 
LVL 1

Expert Comment

by:goldwarlock
ID: 6219566
The name of 1st file has no connection with 2nd
All you need is to handle the Streams!
So jerelw is right
0
 
LVL 1

Expert Comment

by:goldwarlock
ID: 6219614
btw: visit my site
www.xanga.com/goldwarlock
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:pablete
ID: 6223867
Sorry about my lack of knowledge, but I don't know how to do that.

I am using the object MultipartRequest:

MultipartRequest(HttpServletRequest request ,String filePath , int size).

Constructor for class com.oreilly.servlet.MultipartRequest
Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to the given directory, and limiting the upload size to the specified length.

Just creating the object the file is written, I don't get any parameters or anything, so I don't know how to handle the file.

Thanks again,

Pablo




0
 
LVL 3

Accepted Solution

by:
jerelw earned 800 total points
ID: 6225699
public static void writeToFile(String fileName, InputStream is) throws Exception {
    try {
     
       FileOutputStream fos    = new FileOutputStream(new File(fileName));          
       BufferedInputStream bis = new BufferedInputStream(is);          
       
       int c = 0;          
       
       while ((c = bis.read()) != -1) {              
         fos.write(c);          
      }
       fos.flush();
       fos.close();
    }
     catch(Exception e) {
       throw new Exception("Err Writing Contents: " + e);
     }    
  }

use request.getInputStream();

to get your InputStream
0
 

Author Comment

by:pablete
ID: 6226802
Cheers!

Pablo
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question