Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can I read only text files in a directory.

2801625Apr 30 2015 — edited May 1 2015

I've written a program to read files in a directory but I'd like for it to only read the text files of that directory.

import java.io.*;

public class Data {

  public static void main(String[] args) throws IOException {

  String target_dir = "C:\\files";

  File dir = new File(target_dir);

  File[] files = dir.listFiles();

  for (File textfiles : files) {

  if (textfiles.isFile()) {

  BufferedReader inputStream = null;

  try {

  inputStream = new BufferedReader(new FileReader(textfiles));

  String line;

  while ((line = inputStream.readLine()) != null) {

  System.out.println(line);

  }

  } finally {

  if (inputStream != null) {

  inputStream.close();

  }

  }

  }

  }

  }

}

This post has been answered by aJohny on Apr 30 2015
Jump to Answer

Comments

Forms has nothing to do with Reports. Your question should actually be:
"How to print directly from Oracle Reports to the default printer"
All Forms does with regard to Reports is to tell Reports to run a job. What Reports does with that job is a function of Reports and not Forms. Think of it as "fire and forget it". Forms says; " Reports, please run this report...". It is then up to Reports to decide what to do with the result based on how Reports is configured.
That said, there really is no supported way to send a job directly to an individual's default printer because the output of the job is created on the server. You must first bring the output to the user's machine before it can be printed. Once on the local machine it is easy to print it.
Using WebUtil for the task is fairly simple. Just run the report (i.e. RUN_REPORT_OBJECT) then when the output has been created, use WebUtil to download the output file to the local machine. Once on the local machine use WebUtil to open it or send it directly to the printer. If desired, the file can be deleted when finish or whenever you prefer.

Iker Garcia Martin

Hi Michel,
Just run the report then when the output has been created on server.
I use the command webutil_file_transfer.as_to_client('c:/prueba/stockprueba.pdf','/tmp/stockprep.pdf') to download the file to the local machine. Once on the local machine, how send directly to the printer wit webutil?
To delete the file, i use webutil_file.delete_file('c:/prueba/stockprueba.pdf');
Thanks,
Iker

You need to either contact Adobe to determine exactly what command line switches they expose for Acrobat, but as far as I know the following should work on Windows:
"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /t "C:\filetoprint.pdf"
So here is an example of how you might do it in Forms code:

WEBUTIL_HOST.NONBLOCKING ('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /t "C:\myfiletoprint.pdf"');

It is possible that this will result in Acrobat remaining open. This may not be avoidable using this method. There are third party utilities that can be used to directly print and not orphan the executable. Do some Googling ;-)
Again, for help printing PDF files you should contact Adobe. Note there may be some licensing issues associated with attempting to directly print PDF files. I seem to recall that the EULA for Acrobat used to not permit doing this with Acrobat Reader.

1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 29 2015
Added on Apr 30 2015
5 comments
1,039 views