Solved

read file + write file = copy file

Posted on 2003-10-30
2
18,433 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
[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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…
Suggested Courses

732 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