Solved

read file + write file = copy file

Posted on 2003-10-30
2
18,391 Views
Last Modified: 2012-05-04
hi, im trying to read a contents of a file (from a class), store it in a variable/object and pass it to another class and that other class will write it to a file. now im stuck at reading the contents of the file and passing it to another class, ive tried using byte[] as the datatype (i think thats the problem), but it doesnt work. what other datatypes can i use? assuming that the file could be anything (.jpg, .mp3, .zip, etc, etc). what other datatype can i use and how to use them to read/write?
thanks

0
Comment
Question by:Traltixx
2 Comments
 

Expert Comment

by:RobertMarkBram
ID: 9655423
Can you post some code for us to look at?

Usually, reading byte from a file when you don't know the type of file is probably the best way to do it...

Are you getting an exception or something?

Rob
:)
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 25 total points
ID: 9655521

     FileInputStream YourInputStream=new    FileInputStream(YourReadFile);
     File f=new File(YourReadFile);
     byte b[]=new byte[f.length()];
     YourInputStream.read(b);
     B b1=new B();
     b1.write(b,"Your Out Put File");
   //and other codes

where you need to write method in class B and bla bla bla

And I say you are going in right way only. You should use byte array only for reading binary files.

Cheers

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now