Solved

read file + write file = copy file

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 54
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 74
glassfish admin console 1 16
DTD and JAVA versions 1 26
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 video teaches viewers about errors in exception handling.

679 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