How to print a text file using Java
How can I print a text file using Java without converting the output to an image format. Is there anyway I can send the characters in the text file as it is for a print job? I did get a listing doing this ... but that converted the text to an image format before printing....
THanks,.
Hi I had to write a print api from scratch, and I did not convert the output to image. Go and read up on the following code. I know there is a Tutorial on Sun about the differant sections of the snippet.
private void printReport()
Frame tempFrame = new Frame(getName());
PrintJob printerJob = Toolkit.getDefaultToolkit().getPrintJob(tempFrame, "Liesltext", null);
Graphics g = printerJob.getGraphics();
//I wrote the method below for calculations
printBasics(g);
g.dispose();
printerJob.end();
}This alone wont print it you have to do all the calculations in the printBasics method. And as I said I wrote this from scratch and all I did was research first the tutorial and the white papers
Ciao
Similar Messages
-
How to read a text file using Java
Guys,
Good day!
Please help me how to read a text file using Java and create/convert that text file into XML.
Thanks and God Bless.
Regards,
I-Talkpublic void fileRead(){
File aFile =new File("myFile.txt");
BufferedReader input = null;
try {
input = new BufferedReader( new FileReader(aFile) );
String line = null;
while (( line = input.readLine()) != null){
catch (FileNotFoundException ex) {
ex.printStackTrace();
catch (IOException ex){
ex.printStackTrace();
}This code is to read a text file. But there is no such thing that will convert your text file to xml file. You have to have a defined XML format. Then you can read your data from text files and insert them inside your xml text. Or you may like to read xml tags from text files and insert your own data. The file format of .txt and .xml is far too different.
cheers
Mohammed Jubaer Arif. -
How to convert a HTML files into a text file using Java
Hi guys...!
I was wondering if there is a way to convert a HTML file into a text file using java programing language. Likewise I would also like to know if there is a way to convert any type of file (excel, power point, and word) into text using java.
By the way, I really appreciated the help that you guys gave me on my previous topic on how to extract tests from a pdf file.
Thank you....HTML files are already text files. What do you mean you want to convert them?
I think if you search the web, you can find things for converting those MS Office files to text (or extracting text from them, as I assume you mean). -
How to check & unzip zip file using java
Dear friends
How to check & unzip zip file using java, I have some files which are pkzip or some other zip I want to find out the type of ZIp & then I want to unzip these files, pls guide me
thanksHow to check & unzip zip file using java, I have
ve some files which are pkzip or some other zip I
want to find out the type of ZIp & then I want to
unzip these files, pls guide meWhat do you mean "other zip"? Either they're zip archives or not, there are no different types. -
Read Text file using Java Script
Hi,
I am trying to read a text file using Java Script within the webroot of MII as .HTML file. I have provided the path as below but where I am not able to open the file. Any clue to provide the relative path or any changes required on the below path ?
var FileOpener = new ActiveXObject("Scripting.FileSystemObject");
var FilePointer = FileOpener.OpenTextFile("E:\\usr\\sap\\MID\\J00\\j2ee\\cluster\\apps\\sap.com\\xapps~xmii~ear\\servlet_jsp\\XMII\\root\\CM\\OCTAL\\TestTV\\Test.txt", 1, true);
FileContents = FilePointer.ReadAll(); // we can use FilePointer.ReadAll() to read all the lines
The Error Log shows as :
Path not found
Regards,
MohamedHi Mohamed,
I tried above code after importing JQuery Library through script Tag. It worked for me . Pls check.
Note : You can place Jquery1.xx.xx.js file in the same folder where you saved this IRPT/HTML file.
<HTML>
<HEAD>
<TITLE>Your Title Here</TITLE>
<SCRIPT type="text/javascript" src="jquery-1.9.1.js"></SCRIPT>
<script language="javascript">
function Read()
$.get( "http://ldcimfb.wdf.sap.corp:50100/XMII/CM/Regression_15.0/CrossTab.txt", function( data ) {
$(".result").html(data);
alert(data);
// The file content is available in this variable "data"
</script>
</HEAD>
<BODY onLoad="Read()">
</BODY>
</HTML> -
Changing HTML to text file using java
Hi,
I am doing a project in which i have to read news articles from websites. I have tried XML but for that i need to know which tag has the article in it. Since i have to read from various websites so each site used different tags for different informations.
Is there anyway that i can change an HTML file into a text file using java. Maybe some command that removes all the HTML tags and gives just the information. Is there anything else that anyone would like to recommend?
Thanx
yafisMaybe something like this:
import java.io.*;
import java.net.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
class GetHTMLText
public static void main(String[] args)
throws Exception
EditorKit kit = new HTMLEditorKit();
Document doc = kit.createDefaultDocument();
// The Document class does not yet handle charset's properly.
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
// Create a reader on the HTML content.
Reader rd = getReader(args[0]);
// Parse the HTML.
kit.read(rd, doc, 0);
// The HTML text is now stored in the document
System.out.println( doc.getText(0, doc.getLength()) );
// Returns a reader on the HTML data. If 'uri' begins
// with "http:", it's treated as a URL; otherwise,
// it's assumed to be a local filename.
static Reader getReader(String uri)
throws IOException
// Retrieve from Internet.
if (uri.startsWith("http:"))
URLConnection conn = new URL(uri).openConnection();
return new InputStreamReader(conn.getInputStream());
// Retrieve from file.
else
return new FileReader(uri);
} -
How to read some lines from a text file using java.
hi,
i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
we only want to read the file upto the first Occurrence of "TEXT" string.
How to do it ,,,
Kinldy give the code
Regards,
Sagar
this is the text file
dfgjdjj
sfjhjkd
ghjkdg
hjkdgh TEXT
ikeyt
ujt
jk
tyk TEXT
rukl
rHendawy wrote:
Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
Edited by: sabre150 on Apr 29, 2009 2:13 PM -
How to replace a line ina text file using java?
Hi ALL,
Does anybody know how to replace a line in a text file uisng java.use this thing:
http://doesthatevencompile.com/current-projects/code-sniplets/ASCIIFile.htm
open the file,
read its contents, replace the text you need in the contents, set the contents back into the file.
it takes care of the IO for you. -
How to print a text file with long lines?
I am trying to print a text file which contains many long lines. I find that the long lines are truncated on the printouts. How do I wrap up these long lines? Could you give me some examples?
Thank you very much!Here's an example. The "\n" makes anything after it go to the next line. I hope this helps. Look at the Private void getTable() section.
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class LabNine extends Frame implements ActionListener, WindowListener {
private TextField txtInfo;
private List lstInfo;
private Button btnAddInfo;
private BorderLayout borderlayout;
private Connection databaseConnection;
Statement statement;
ResultSet resultSet;
public LabNine( ) {
super("Lab Nine");
// addWindowListener to close application
addWindowListener(this);
// create layout
borderlayout = new BorderLayout();
setLayout(borderlayout);
// create text field so the file input that is selected will be seen in here
txtInfo = new TextField();
txtInfo.setEnabled(false);
Color color = new Color(255, 136, 183);
txtInfo.setBackground(color);
add(txtInfo, BorderLayout.NORTH);
// create list so the file input can be populated in here
lstInfo = new List();
add(lstInfo, BorderLayout.CENTER);
// create button to add selected input file in the text field
btnAddInfo = new Button("Add Info");
btnAddInfo.setBackground(Color.cyan);
btnAddInfo.setFont(new Font("TimesRoman", Font.BOLD, 16));
btnAddInfo.addActionListener( this );
add(btnAddInfo, BorderLayout.SOUTH);
// set frame attributes
setSize(450, 250);
setResizable( false );
show();
// get the table/ get the query
loadConnection();
getTable();
public void actionPerformed(java.awt.event.ActionEvent e) {
// if add button is pushed then it will check to see if an item was selected.
// if not, then an error message will be displayed else the selected item will be in the text box
if ( e.getSource() == btnAddInfo ) {
if ( lstInfo.getSelectedIndex() == -1 ) {
System.out.print( "You have not selected an item" );
else {
txtInfo.setText(( lstInfo.getSelectedItem() ));
private void getTable() {
try {
String query = "SELECT FIRST, LAST, EMAIL FROM Names";
statement = databaseConnection.createStatement();
resultSet = statement.executeQuery( query );
while ( resultSet.next() ) {
lstInfo.add( resultSet.getString( "FIRST" ) + " " + resultSet.getString( "LAST") + " " +
resultSet.getString( "EMAIL" ) + "\n" );
statement.close();
catch ( Exception e ) {
System.err.println( e );
private void loadConnection() {
// define the data source for the driver
String sourceURL = "jdbc:odbc:people";
String username = "";
String password = "";
// load the driver
try {
// load the drive class
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
// create a connection through the drivermanager
databaseConnection = DriverManager.getConnection( sourceURL , username, password );
catch( ClassNotFoundException cnfe ) {
System.err.println( cnfe );
catch( SQLException sqle ) {
System.err.println( sqle );
public static void main(java.lang.String[] args) {
LabNine aLabNine = new LabNine( );
public void windowActivated(java.awt.event.WindowEvent e) {
public void windowClosed(java.awt.event.WindowEvent e) {
// closes the application
System.exit( 0 );
public void windowClosing(java.awt.event.WindowEvent e) {
// closes the application
System.exit( 0 ); -
How to Run a text files using UNIX
Hi,
I have 10 text files in my project my task is to load all the text files data into Relational Database so i can use sql*loader to load all the text files data into a Database.
but the thing is another project i have 200 text files so i need to run these text files using UNIX script could anyone tell me how to load all the text files using UNIX
Thank's
Edited by: Lavanya on Sep 5, 2012 3:09 PMLavanya,
This question relates to shell scripting and in IMO it is not an oracle question.
I have made some initial assumptions before my proposed solution.
PLEASE note that this is untested, but can just guide you as a template for solving your problem.
Assuming that you have properly set up the control file and mapped each and every table in it as per the file information which you have..
Assuming the text file to be in the format of : ------ (as suggested by other posters earlier, this file holds instructions about the file and table mapping which shall be used by your sqlldr process.)
tmp.txt:
text_file_1-------------should goes to----customer_info_table
text_file_2------------should goes to------customer_address_table
text_file_3-----------should goes to-------customer_order_table
while read line
do
SQLLDR CONTROL=`echo $line | sed 's/should goes to/ /g' | sed 's/-//g' | awk -F " " '{print $1}'`.ctl,
LOG=`echo $line | sed 's/should goes to/ /g' | sed 's/-//g' | awk -F " " '{print $1}'`.log,
BAD=`echo $line | sed 's/should goes to/ /g' | sed 's/-//g' | awk -F " " '{print $1}'`.bad,
DATA=`echo $line | sed 's/should goes to/ /g' | sed 's/-//g' | awk -F " " '{print $1}'`.txt
USERID=scott/tiger
done <tmp.txtAll I am trying to run from the above shell script is : -- PLEASE TEST it if it matches your requirement.
SQLLDR CONTROL=text_file_1.ctl, LOG=text_file_1.log, BAD=text_file_1.bad, DATA=text_file_1.txt USERID=scott/tiger
SQLLDR CONTROL=text_file_2.ctl, LOG=text_file_2.log, BAD=text_file_2.bad, DATA=text_file_2.txt USERID=scott/tiger
SQLLDR CONTROL=text_file_3.ctl, LOG=text_file_3.log, BAD=text_file_3.bad, DATA=text_file_3.txt USERID=scott/tigerRepeating my assumptions, I assume you have all those files required for SQLLDR process to run (ctl file, data file...)
Cheers,
Manik -
How to print a text file with pagebreak.......
hi to all,
i am new in java and i want to do print a text file with page break. that text file is converted from html view page with help of htmlconveter class and i want to set page break in the text file.ASCII 12 is not work properly.its not break a page in proper manner.plz reply soon.hi to all,
i am new in java and i want to do print a text file with page break. that text file is converted from html view page with help of htmlconveter class and i want to set page break in the text file.ASCII 12 is not work properly.its not break a page in proper manner.plz reply soon. -
How to download a text file using classes
Hi Guys
I want to download a text file using classes.
Any idea how to do it ?
Thanks
SameerHI sameer,
It is no different from using a Function module.
example:
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = w_fpath
append = SPACE
write_field_separator = 'X'
CHANGING
data_tab = it_download
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24
Regards,
ravi -
Displaying of a text file using JAVA in a browser.
Please can you give me the code for displaying of a text file using a bean and java coding. Please include all files needed. Thanks
please could you give us 200 Uss each for the work done for you plz include all needed recipes plz? thx
-
How to read a text file using adobe javascript
Hi,
I have a api application which adds toolbar to a adobe acrobat. i need to disable the toolbar according to expiry date, So i need to fetch the expiry datge from a text file from the specified location.
I am using importTextData() function to get the textdata from text file using adobe javascript. When i call this function i am getting error "ReferenceError: importTextData() is not defined".
I am using Adobe Acrobat 7.0 version.
Can any one tell how to use the importTextData() function.
Regards
Shivacalling from javascript file which is placed in the below location.C:\\Program Files (x86)\\Adobe\\Acrobat 7.0\\Acrobat\\Javascripts
Regards
Shiva -
How to format a excel file use java.
hi,
everyone, i meet a problem.i want to write a excel file use java.i can use .csv input the date to excel.but i want to know how to format it.
thanks
Jovehi,
everyone, i meet a problem.i want to write a excel
el file use java.i can use .csv input the date to
excel.but i want to know how to format it.
thanks
JoveIf I understand your question correctly you need to know the format of a .csv file for use in an Excel spreadsheet. A .csv file is a comma-delimited file so all that you need to do is write your data elements to the file with commas in between them. Having done something similar in the past, let me warn you that when Excel is reading your file, it uses some characters other than commas as field delimiters. for example, / : and ; are treated as commas. To defeat this, you will need to surround fields containing those characters in double quotes.
Hope that helps
Mark
Maybe you are looking for
-
Moving time-dependant data from one table to another (archiving)
Hello all I would like to know if there's an easier solution or a "best practice" to move data from one table to another. The context of this issue can be found within "archiving". More concretely: we have an application that uses several tables to l
-
How can I know my iPad is 3rd generation?
How can I know my iPad is 3rd generation?
-
I've followed all support steps and my ipod mini wont go into manual disk mode. The apple icon never leaves...I've downloaded update and tried everything. I just got this one from apple as a replacement as my old one stopped working too. This one wor
-
What is generalization, aggregation and specification in database abstraction ?
What is generalization, aggregation and specification in database abstraction ?
-
I have a iphone 4s on ios6 battery run down fast help plz
I have a iphone 4s on ios6 battery run down fast help plz