[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

read file + write file = copy file

Posted on 2003-10-30
2
Medium Priority
?
18,454 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 75 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 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