How do I open a Website/HTML file from an Application in a Browser (IE is fine)

F

Flo

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.
 
M

Mich

Flo said:
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();
}
}

}
 
A

Andrew Thompson

Flo said:
Hey guys,
very basic question:

Note: "What is the meaning of life?" is also
a very basic question. It's the answer that
is more tricky.
I want to push a button, and open an HTML file in Internet Explorer (or
any browser, ..

- For an applet, showDocument(url) easy but unreliable.
- For an application BrowserLauncher in older Java versions
(reliable, with feedback, but requires an extra 20-40K
of jar), though I vaguely though I heard of some JDIC
project or perhaps a feature in latest Java that claimed
to hook into browser launching.
- For a web-started applet or application,
BasicService.showDocument(url), easy, reliable and
provides feedback.

HTH

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top