Version 1


    Why am I getting the above error on the code bellow  (FileSaveService and FileContents work just fine):

     

     

    com.hrtrust.ps.scanner;






    javax.jnlp.FileOpenService;


    javax.jnlp.FileSaveService;


    javax.jnlp.FileContents;


    javax.jnlp.ServiceManager;


    javax.jnlp.UnavailableServiceException;


    java.io.*;


    javax.jnlp.ExtendedService;



    class FileHandler {



    static private FileOpenService fos = null;


    static private FileSaveService fss = null;


    static private FileContents fc = null;


    static private ExtendedService exs = null;



    // retrieves a reference to the JNLP services


    private static synchronized void initialize() {


    if (fss != null) {


    return;



    try {


    fos = (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService");


    fss = (FileSaveService) ServiceManager.lookup("javax.jnlp.FileSaveService");


    exs = (ExtendedService) ServiceManager.lookup("javax.jnlp.ExtendedService");        



    catch (UnavailableServiceException e) {


    fos = null;


    fss = null;


    exs = null;





    public static FileContents getDLL(File dllFile) {



    try {


    fc = exs.openFile(dllFile);


    catch (IOException ioe) {


    ioe.printStackTrace(System.out);


    return null;




    return fc;




    // displays open file dialog and reads selected file using FileOpenService


    public static String open() {



    try {


    fc = fos.openFileDialog(null, null);


    return readFromFile(fc);


    catch (IOException ioe) {


    ioe.printStackTrace(System.out);


    return null;





    // displays saveFileDialog and saves file using FileSaveService


    public static void save(String txt) {



    try {


    // Show save dialog if no name is already given


    if (fc == null) {


    fc = fss.saveFileDialog(null, null,


    new ByteArrayInputStream(txt.getBytes()), null);


    // file saved, done


    return;



    // use this only when filename is known


    if (fc != null) {


    txt, fc);



    catch (IOException ioe) {


    ioe.printStackTrace(System.out);





    // displays saveAsFileDialog and saves file using FileSaveService


    public static void saveAs(String txt) {



    try {


    if (fc == null) {


    // If not already saved. Save-as is like save


    txt);


    else {


    fc = fss.saveAsFileDialog(null, null, fc);


    txt);



    catch (IOException ioe) {


    ioe.printStackTrace(System.out);





    private static void writeToFile(String txt, FileContents fc) throws IOException {


    int sizeNeeded = txt.length() * 2;


    if (sizeNeeded > fc.getMaxLength()) {


    fc.setMaxLength(sizeNeeded);



    os = new BufferedWriter(new OutputStreamWriter(fc.getOutputStream(true)));


    os.write(txt);


    os.close();




    private static String readFromFile(FileContents fc) throws IOException {


    if (fc == null) {


    return null;



    br = new BufferedReader(new InputStreamReader(fc.getInputStream()));


    sb = new StringBuffer((int) fc.getLength());


    line = br.readLine();


    while (line != null) {


    sb.append(line);


    sb.append("\n");


    line = br.readLine();



    br.close();


    return sb.toString();