samedi 31 janvier 2015

java.lang.StringIndexOutOfBoundsException: String index out of range: 11


Vote count:

0




I have write the below code for print any type of file but it is giving error String index out of range: 11 is there any problem with the code.


package PrintFile;



import javax.print.*;
import javax.print.attribute.*;
import java.io.*;

public class Printing {

public Printing(String path)
{
file = new File(path);
}

public static void Print() throws Exception
{
//String filename = (Path); // THIS IS THE FILE I WANT TO PRINT
//file = new File(path);

PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; // MY FILE IS .txt TYPE
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);

if (service != null)
{
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(file);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
Thread.sleep(10000);
}
System.exit(0);
}

private File file;

}


asked 49 secs ago







java.lang.StringIndexOutOfBoundsException: String index out of range: 11

Aucun commentaire:

Enregistrer un commentaire