Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How do I open a Website/HTML file from an Application in a Browser (IE is fine)

Reply
Thread Tools

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

 
 
Flo
Guest
Posts: n/a
 
      01-09-2007
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.

 
Reply With Quote
 
 
 
 
Mich
Guest
Posts: n/a
 
      01-09-2007

"Flo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.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(fil eString);
return fileBytes;
}

/**
* @written: 07.11.2001
* @version: 1.0
* @tested: yes
* @usage: compukat.io.Read.fileInputStreamString(String):Str ing
*/
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(InputStreamRead er):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.toStri ng()};
return response;
}

/**
* @written: 07.11.2001
* @version: 1.0
* @tested: yes
* @usage: compukat.io.Read.urlConnection(URLconnection):Stri ng
*/
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();
}
}

}


 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-10-2007
Flo wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
I really need webbrowser.open('file://') to open a web browser Timur Tabi Python 4 01-18-2010 09:00 PM
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
Force browser to open a file (rather than save/open/cancel) tiewknvc9 Java 12 02-19-2007 08:21 PM
Open .msg / .eml file in Browser/placeholder within browser ai4u ASP .Net 0 04-27-2006 11:29 AM



Advertisments