-
package full_projects;
-
/*--------------------------------------------------------------------------
-
//Author List:
-
//deAppel
-
//
-
//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
-
// 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");
-
}
-
-
}
-
else{
-
}
-
-
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");
-
}
-
-
IOE.printStackTrace();
-
-
}
-
else{}
-
-
-
System.
out.
println("Please connect to the internet first..");
-
-
-
e.printStackTrace();
-
}
-
}
-
}
[...] HappyFace wrote an interesting post today on Updating a textfile trough the netHere’s a quick excerptIt can be used to update an application or whatever you want to update but this version can only update a textfile. I’ll release a new version soon that demonstrates how to update a file/application when connected to the internet. … [...]