Results 1 to 5 of 5
  1. #1
    yoganeethi is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Unhappy How to print text file in java(dotmatrix printer)

    How to print text file in java(dotmatrix printer).Can u plz send the source code.......

  2. #2
    gulapala is offline Member
    Join Date
    Dec 2007
    Posts
    11
    Rep Power
    0

    Default

    First do some howe work before raising such open questions. It will always help you even if some one gives you the code. By simple giving you the source code, will not in any way help you. So please try to do some work on it and if it is done, let the forum members know what is the issue and why you were not able to succeed it.
    Thanks & Regards, G.Rajasekhar

  3. #3
    sandy1000's Avatar
    sandy1000 is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    package mypackage;
    import java.io.*;

    public class SimplePrinting {
    public static String strLine;
    public static String strLine1="";


    public static void main(String[] args) {
    try{
    // Open the file that is the first
    // command line parameter
    FileInputStream fstream = new FileInputStream("c:\test.txt");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    //Read File Line By Line
    while ((strLine = br.readLine()) != null) {
    // Print the content on the console
    strLine1 = strLine1 + strLine;
    }
    //Close the input stream
    in.close();
    }catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }

    try {
    FileWriter out = new FileWriter("lpt1");
    out.write(strLine1);
    out.write(0x0D); // CR
    out.close();
    }
    catch (IOException e) {
    e.printStackTrace();
    }
    }
    }

  4. #4
    sandy1000's Avatar
    sandy1000 is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by yoganeethi View Post
    How to print text file in java(dotmatrix printer).Can u plz send the source code.......
    i have posted a program.This program should work.

  5. #5
    xacml's Avatar
    xacml is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default

    Instead of using static fields; you should prefer method specific parameters. And stringBuilder is more reasonable for String append operation.

    Java Code:
    package mypackage;
    
    import java.io.*;
    
    public class SimplePrinting {
    
    	public static void main(String[] args) {
    		String line;
    		StringBuilder textBuilder = new StringBuilder();
    		try {
    			// Open the file that is the first
    			// command line parameter
    			FileInputStream fstream = new FileInputStream("c:\\pending.un");
    			BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
    			// Read File Line By Line
    			while ((line = br.readLine()) != null) {
    				// Print the content on the console
    				textBuilder.append(line);
    			}
    			// Close the input stream
    			br.close();
    		} catch (Exception e) {// Catch exception if any
    			System.err.println("Error: " + e.getMessage());
    		}
    		// you can check it with printing to sysOut
    //		System.out.println(textBuilder.toString());
    		
    		try {
    			FileWriter out = new FileWriter("C:\\misal.txt");
    			out.write(textBuilder.toString());
    			out.write(0x0D); // CR
    			out.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    }

Similar Threads

  1. Sending text to printer
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 05-25-2009, 06:14 AM
  2. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM
  3. Replies: 0
    Last Post: 08-09-2007, 06:30 AM
  4. jsp program for client side printer to print these 2 strings on 3/3
    By for453 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-07-2007, 04:42 PM
  5. Replies: 0
    Last Post: 08-06-2007, 06:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •