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>

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.

and don't do that using JSP, it's not meant for it.

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.

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.

in fact kid, my contribution was way more helpful than yours which would have him go on doing things all the wrong way...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.