RSS Forums RSS
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1159 | Replies: 5 | Thread Tools  Display Modes
Reply
Join Date: May 2007
Posts: 3
Reputation: ashitha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ashitha ashitha is offline Offline
Newbie Poster

how the multiple file can be copied and write into the another file

  #1  
May 12th, 2007
hello...
i am write a programme for copy file and stores into each another file.like this way i want to copy multiple files.but the error null pointer is coming.. why the value is not displayed?I can't understand null pointer exception..
the code
<%@ page language="java"%>
<%@ page import="java.io.*"%>
<%@ page import="java.text.*"%>
<html>
<head>
<title>
</title>
</head>
<body>
<%
try
{

String cname=request.getParameter("cname");
String category=request.getParameter("category");
String submit=request.getParameter("submit");
int len;
File f1=new File(request.getParameter("file"));
File f2=new File("ee/file1.txt");

InputStream is=new FileInputStream(f1);
OutputStream os=new FileOutputStream(f2);

byte buf[]=new byte[1024];


%>
Company Name is:<%out.println(cname);%>
Category :<%out.println(category);%>
<%

while((len=is.read(buf))>0)
{
os.write(buf,0,len);
out.println("file copied");
}


is.close();
os.close();
out.println("file copied");
}
catch(FileNotFoundException ex)
{
out.println(ex);
}
catch(IOException eo)
{
out.println(eo);
}
catch(Exception e)
{
out.println(e);
}

finally
{
out.println("");
}
%>

</body>
</html>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,594
Reputation: masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all 
Rep Power: 11
Solved Threads: 147
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: how the multiple file can be copied and write into the another file

  #2  
May 12th, 2007
Stick to one thread. Either in this post, or your other one, post the code again (using code tags this time). Post, also, the complete error message and comment the line referenced in the error message.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,749
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: how the multiple file can be copied and write into the another file

  #3  
May 12th, 2007
and don't do that using JSP, it's not meant for it.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: how the multiple file can be copied and write into the another file

  #4  
May 18th, 2007
Add some debug code, skip the actual file write for now... place output statements to show the values of the parameters... if you try to read a parameter that doesn't exist you will have a problem... if you try to create a file with a null object which would be the result of trying to read a parameter that doesn't exist, then you would have a problem....

If your output file object isn't being create properly and you try to write to it, you will have a problem....

Add robust output to the screen, separate parameter reads and file object creation, use if(object == null) tests prior to using input and output objects, etc. so you know exactly where the error is being thrown and what the state of each variable is at the time...

Try to write the document to the screen... then test with a text file NOT a binary file... along with the other output so you see if you are reading it OK...

Finally if you see not trouble with the parameters or read process then re-enable to write process and focus your debug there....

The problem, as I see it, is that you are not UPLOADING the file... you are looking for the upload file as a local file, and that is NOT how you do it...

To upload the file you need to use a different method... apache software foundation (I think) has some good open source libraries for handling the upload of the document... see the document upload has to be handled using a very different method from other form parameters...

Peace,

P.S. they are right though, you should post your new messages as replies to the same thread you started previously not create a new thread for each posting you make...

BUT, masijade you should be a little more tolerant in how you say such things, a new poster may not know and if this guy is not a native English speaker, or not very good at it, they may have a hard time figuring out to use the site the best way... Be a little more tolerant and polite in how you voice such things or take a deep breath and count to 10 prior to posting...

and jwenting... just stop posting all together since you obviously have nothing useful to add.
Reply With Quote  
Join Date: Feb 2006
Posts: 1,594
Reputation: masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all 
Rep Power: 11
Solved Threads: 147
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: how the multiple file can be copied and write into the another file

  #5  
May 18th, 2007
I'm sorry, but, you are not a member of the Politeness Police here. Nothing I said was rude. It was not especially polite, but it was not rude. They were simple directions and statements of fact.

I am not here to be polite (although I am not deliberately rude unless the poster has demonstrated his/her own disregard for others). I am here, to at least attempt, to help people, but I do not always have the time to be ultra polite or overly explanatory in my posts, so you get something like my post above.

I have nothing to be ashamed of in that post, as I did nothing wrong, and I provided him with advice that he needed.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,749
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: how the multiple file can be copied and write into the another file

  #6  
May 18th, 2007
in fact kid, my contribution was way more helpful than yours which would have him go on doing things all the wrong way...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the JSP Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:36 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC