GeSHi (java):
package full_projects;
/*--------------------------------------------------------------------------
//Author List:
//deAppel <Creator>
//
//Description:
// An example of updating a textfile trough the net.
//
//Environment:
//This software was developed using Eclipse and Java 1.6
//
//Copyright Information:
//Copyright (C) 2007 <Institution><None>
// Ark de Appel www.engineeringserver.com
//
//----------------------------------------------------------------------*/
import java.io.*;
import java.net.*;
import javax.swing.JOptionPane;
public class UpdaterDemo {
System.
out.
println("This demo will update a textFile from a server");
UpdaterDemo gr = new UpdaterDemo();
gr.Update();
}
public void Update(){
String currentVersion =
"1.0";
try {
s =
new Socket("127.0.0.1",
80);
p.print("GET /update/file.txt HTTP/1.0\r\n");
p.print("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0\r\n");
p.print("Connection: close\r\n\r\n");
int lines = 0;
while ((line = buffer.readLine()) != null && lines < 9){
lines++;
}
System.
out.
println("Current textfile version: " + currentVersion
);
if ((line = buffer.readLine()).equals(currentVersion)){
System.
out.
println("Textfile up to date! Version: " + line
);
}
else{
System.
out.
println("Updating to: " + line +
" please hold on.");
currentVersion = line;
while ((line = buffer.readLine()) != null ) {
if(!(line.equals("") && lines == 9)){ //remove the spaces in the new textfile!
bwUpdate.write(line);
bwUpdate.newLine();
lines++;
}
}
bwUpdate.close();
in.close();
System.
out.
println("Updated to version: " + currentVersion +
"!");
System.
out.
println("Happy reading!");
}
File fFF =
new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
if (fFF.exists())
try{
Runtime.
getRuntime().
exec("C:\\Program Files\\Mozilla Firefox\\firefox.exe c:\\updateFile.txt http://www.engineeringserver.com/t3hc0d3z/index.php");
//Runtime.getRuntime().exec("C:\\Program Files\\Mozilla Firefox\\firefox.exe http://www.engineeringserver.com/t3hc0d3z/index.php");
}
//IOE.printStackTrace();
}
else{
//System.out.println("");
}
File fIE =
new File("C:\\Program Files\\Internet Explorer\\iexplore.exe");
if (fIE.exists() && !fFF.exists())
try{
Runtime.
getRuntime().
exec("C:\\Program Files\\Internet Explorer\\iexplore.exe c:\\updateFile.txt http://www.engineeringserver.com/t3hc0d3z/index.php");
//Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore.exe c:\\engineeringserverTMP.html");
}
IOE.printStackTrace();
}
else{}
System.
out.
println("Please connect to the internet first..");
e.printStackTrace();
}
}
}
Created by GeSHI 1.0.7.20
Sample output:This demo will update a textFile from a server
HTTP/1.1 200 OK
Date: Mon, 27 Aug 2007 17:11:27 GMT
Server: Apache/2.0.55 (Win32) PHP/4.4.2
Last-Modified: Mon, 27 Aug 2007 17:11:23 GMT
ETag: "2cf5d-60-7235a67d"
Accept-Ranges: bytes
Content-Length: 96
Connection: close
Content-Type: text/plain; charset=ISO-8859-1
Current textfile version: 1.0
Updating to: 1.1 please hold on.
Updated to version: 1.1!
Happy reading!