This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I need to print a text file (say e.g 'bar.txt') from a Java Source Code. Let's say I specify the name of the text file (e.g. 'bar.txt') in my Java Source Code and when I run the Java Code, it should print the text file in the printer. Can anybody tell me, what I need to do? Please specify a block of Code if possible... Thanks. Cheers! Ash
Joined: Mar 13, 2003
Yes, friends...I defnitely mean a printer...and not just 'System.out.println'............ Thanks... Cheers! Ash
The above two links posted by Robert are good for printing but it does not solve my purpose. What I am looking out is to specify a file name (e.g. 'bar.csf'), might be as an instance of FileOutoutStream and need to print the same from a Java Source Code. Cheers! Ashim
The Print API doesn't specify where the information comes from. If you create an appropriate stream object to read your file, then you can read the info to the stream and use the Print API to print it out. If you don't know how to open a file stream for reading, then that is a different question entirely. HTH Layne [ March 13, 2003: Message edited by: Layne Lund ]
First of all , thank you everybody for all your inputs. What I have seen from most of you, is that people put suggestions which they haven't themseleves tried it out. I know, I can send FileOutputStream object for the file and then make the Print API's to print it. That is what I have already suggested. Please don't repeat my suggestion as your reply.
What I need, is a working block of code, which you have already tried out previously. If you have a working block of code to do the same, then please put it up. I will be grateful to you. Please don't repeat my suggestion as your reply. Thanks everybody. Cheers! ASH Certified by IBM, ORACLE, SUN MICROSYSTEMS AUDITOR FOR ISO 9001:2000
Originally posted by Ashim Kumar: What I have seen from most of you, is that people put suggestions which they haven't themseleves tried it out.
hmmmm . . . Have YOU tried it out? If you won't do it for yourself - why would anyone else? :roll: If you look at Example2 in the references above, it shows you how to print a String to the printer. You could just read your file into a String and feed that into the example that you were given. Do you understand how to read your file into a String?? If so, do you understand where it is that you would modify the example to use your String instead of the one hardcoded in the example? You were looking for MORE specific than that???
"JavaRanch, where the deer and the Certified play" - David O'Meara
What's a CSF file anyway? What type of application uses it? What should the printed output look like? You probably need to find a tool that understands the format of a given file in order to render it visually in an appropriate manner.
"I'm not back." - Bill Harding, Twister
Joined: Mar 13, 2003
First of all, I would like to thank you all for your suggestions. Unfortunately, it doesn't match up with the kind of requirement I have. Perhaps, it is my mistake that I didn't explain my requirement clearly. Here it goes, I have a file (say 'bar.csf'). Now this file is similar to any other text file except that it has certain ASCII characters in it. Now the same file is fed to a special barcode printer for printing bar code labels. All that I need to do is to print the same file from a Java block of code directly WITHOUT any modification or conversions. Hence if the file is converted into a Swing Component or a Java String doesn't really solve my purpose. Thus even though, the first two suggestion are excellent but doesn't solve my purpose in my case. All that I need to do is to print the file directly. Now I did receive some important clue in doing that. I believe JDK 1.4 has javax.print and specially the class 'StreamPrintService' can help me in doing that. I am digging into that. Any further suggestions are really welcome. Thanks once again. Cheers! Ash
I believe that JDK 1.4 provides support for printing text files directly through java.print API's There is an example on the Sun Site which explains how to print a text file, images files etc. to a printer. The link for the same below http://access1.sun.com/tools/JPSDemo/jpsdemo.html One more reference to the FORUM: I think all messages are meant for everybody in general and not specific and personal to anybody. There was no need for Cindy Glass to be personal and be stupid. I hope she doesn't want to scare everybody with her gun !!! (See Profile) Regards, Kathy