Re: How do I open a Website/HTML file from an Application in a Browser (IE is fine)
 
"Flo" <f.ruecker@gmail.com> wrote in message
news:1168375784.891044.44990@i39g2000hsf.googlegroups.com...
Hey guys,
very basic question:
I want to push a button, and open an HTML file in Internet Explorer (or
any browser, there's no need for very compatible code, since the
software will only be used a couple of times on a windows machine).
Important: I do NOT want to have the HTML file viewed with java or
JEditPane or whatever..
Thank you!
Flo.
package compukat.io;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.FileInputStream;
import org.apache.commons.httpclient.HttpClient;
public class Read {
   public static String read(String file) throws IOException {
     return fileInputStreamString(file);
   }
/**
* @written: 07.11.2001
* @version: 1.0
* @tested:  no
*/
public static String bufferedReader(BufferedReader bufferedReader) throws
IOException {
  StringBuffer stringBuffer = new StringBuffer("");
  String line = bufferedReader.readLine();
  while (line!=null) {
    // If this is the first line (i.e.,text = null), do not add it,
    stringBuffer.append(line+'\n');
    line = bufferedReader.readLine();
  }
  bufferedReader.close();
  return stringBuffer.toString();
}
/**
* @written: 07.11.2001
* @version: 1.0
* @tested:  yes
* @usage:   compukat.io.Read.fileinputStream(FileInputStream):String
*/
static public String fileInputStream(FileInputStream fileInputStream) throws
IOException {
        return inputStream(fileInputStream);
}
  /**
  * @written: 2002.02.04
  * @version: 1.0
  * @tested:  no
  * @usage:   new compukat.io.Read().fileInputStreamByte(String
fileName):byte[]
  */
  public byte[] fileInputStreamByte(String infile) throws IOException {
    String fileString = fileInputStreamString(infile);
    byte[] fileBytes  = new
compukat.conversion.StringConversion().toBytes(fileString);
    return fileBytes;
  }
  /**
  * @written: 07.11.2001
  * @version: 1.0
  * @tested:  yes
  * @usage:   compukat.io.Read.fileInputStreamString(String):String
  */
  static public String fileInputStreamString(String file) throws IOException
{
    File file_ = new File(file);
    if(!file_.exists()) {
      throw new IOException("File ".concat(file).concat(" does not exist"));
    }
    return fileInputStream(new FileInputStream(file));
  }
  static public String file2String(String file) throws IOException {
    String string = null;
    if (FileUtil.fileExists(file)) {
       string = fileInputStreamString(file);
    }
    return string;
  }
   /**
   * @written: 07.11.2001
   * @version: 1.0
   * @tested:  yes
   * @usage:   compukat.io.Read.inputStream(InputStream):String
   */
   static public String inputStream(InputStream infile) throws IOException {
      int b = 0;
      StringBuffer fileContent = new StringBuffer();
      b = infile.read();
      while(b != -1) {
         fileContent.append((char)b);
         b = infile.read();
      }
      infile.close();
      return fileContent.toString();
   }
/**
* @written: 07.11.2001
* @version: 1.0
* @tested:  no
* @usage:   compukat.io.Read.inputStreamReader(InputStreamReader):String
*/
static public String inputStreamReader(InputStreamReader inputStreamReader)
throws IOException  {
   return bufferedReader(new BufferedReader(inputStreamReader));
}
/**
* @written: 07.11.2001
* @version: 1.0
* @tested:  yes
* @usage:   compukat.io.Read.url(URL):String
*/
   public static String url(URL url) throws IOException {
      HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
      String response = urlConnection(urlConnection);
      return response;
   }
   static public String[] urlConnection(URL url) throws IOException {
      HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
      String[] response =
{urlConnection(urlConnection),urlConnection.toString()};
      return response;
   }
  /**
  * @written: 07.11.2001
  * @version: 1.0
  * @tested:  yes
  * @usage:   compukat.io.Read.urlConnection(URLconnection):String
  */
  static public String urlConnection(URLConnection urlConnection) throws
IOException {
    return Read.inputStream(urlConnection.getInputStream());
  }
  /**
  * @written: 07.11.2001
  * @version: 1.0
  * @tested:  yes
  * @usage:   compukat.io.Read.urlString(String):String
  */
  static public String urlString(String urlString) throws IOException {
   URL url = new URL(urlString);
   return Read.url(url);
  }
  static public String[] urlStringConnection(String urlString) throws
IOException {
   URL url = new URL(urlString);
   return Read.urlConnection(url);
  }
  public static void main(String[] args) {
    String url = "http://www.tambu-smart.com/cat1.html";
    try {
      String page = compukat.io.Read.urlString(url);
      page = compukat.string.Edit.parseTo(page,"http://www.");
      url = compukat.string.Edit.extractPast(page,".com");
    }
    catch(Exception e) {
       e.printStackTrace();
    }
  }
}