Solved

com.oreilly.servlet question

Posted on 2001-06-22
6
218 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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 200 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

691 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