The Artima Developer Community
Sponsored Link

Java Answers Forum
File reading problem

1 reply on 1 page. Most recent reply: Dec 13, 2004 11:07 PM by Gunasekhar

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
faraday

Posts: 3
Nickname: sharmrkf
Registered: Nov, 2004

File reading problem Posted: Dec 13, 2004 8:57 AM
Reply to this message Reply
Advertisement
Hello, I read some of the java docs, but examples-mainly- focus on .txt files, I am having difficulties to read from different files, like .pdf, or .xls, part of my program:

FileRead f = new FileRead();

f.readFile();
}

void readFile() {

DataInputStream dis = null;

String record = null;

int count = 0;
try {

File f = new File("myfile.pdf");

FileInputStream fis = new FileInputStream(f);

BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);

while ( (record=dis.readLine()) != null ) {

count++;

System.out.println(recCount + ": " + record);
}


thanks for your help.


Gunasekhar

Posts: 7
Nickname: dguna
Registered: Nov, 2004

Re: File reading problem Posted: Dec 13, 2004 11:07 PM
Reply to this message Reply
Hi

You can use following code:

import java.io.*;

public class TempClass {
public static void main(String[] args) {

TempClass f = new TempClass();

f.readFile();
}

public void readFile() {
try {
FileOutputStream fos = new FileOutputStream("myfile2.pdf");
FileInputStream fis = new FileInputStream("myfile.pdf");
int ch;
while ( (ch = fis.read()) != -1 ) {
fos.write(ch);
}
fos.close();
fis.close();
}
catch(Exception e){e.printStackTrace();}
}
}

Flat View: This topic has 1 reply on 1 page
Topic: type casting & narrowing Previous Topic   Next Topic Topic: incompatiple types how to sort it, help pls

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use