2 Very useful java class for web developing
3 posters
Page 1 of 1
2 Very useful java class for web developing
Well, it's been some time since i have last shared something with you guys. I didn't learn much though else i would have shared it.
Now, I do know that, not much of you are doing web developing works. But someday you will. That time you may find these 2 classes very helpful.
A few days ago, I got a .doc file to be converted to html page which again would have to have fields that could be filled dynamically. Quite a task for me.
The first challenge was met easily with the help of Amit. Now I have to convert this page to php page in order to do surgical work on it. You might say that, "eh...that's easy!! just have some echo(); before each line."
In this case, there are two problems.
1. If the file is too large (mine was 1500 lines) and you're gonna do it manually..(well, what can i say then?).
2. If the page has double quotes, then they must be changed to single quote before you can use echo(""); method with them.(R U gonna do it 'manushally'???)
At first i thought i would be able to do them by hand!!
BEHOLD!!! I have solved both problem's by 3 hrs of java coding and 4 smokes.(smoke may not work on you though). I am giving you 2 java classes that would change your html source code page to php, with just 2 CTRL+F11's. You would find file reading and writing codes on the internet but these codes are customized to serve your purpose.
Run the first one to solve prob number 2.
Now run the second one to add echo's with each line.
fianally just add php tag and other functions as necessary.
Let me know if you find it helpful.
Now, I do know that, not much of you are doing web developing works. But someday you will. That time you may find these 2 classes very helpful.
A few days ago, I got a .doc file to be converted to html page which again would have to have fields that could be filled dynamically. Quite a task for me.
The first challenge was met easily with the help of Amit. Now I have to convert this page to php page in order to do surgical work on it. You might say that, "eh...that's easy!! just have some echo(); before each line."
In this case, there are two problems.
1. If the file is too large (mine was 1500 lines) and you're gonna do it manually..(well, what can i say then?).
2. If the page has double quotes, then they must be changed to single quote before you can use echo(""); method with them.(R U gonna do it 'manushally'???)
At first i thought i would be able to do them by hand!!
BEHOLD!!! I have solved both problem's by 3 hrs of java coding and 4 smokes.(smoke may not work on you though). I am giving you 2 java classes that would change your html source code page to php, with just 2 CTRL+F11's. You would find file reading and writing codes on the internet but these codes are customized to serve your purpose.
Run the first one to solve prob number 2.
- Code:
import java.io.*;
public class fileJava {
public static void main(String args[]){
try {
fileJava j = new fileJava();
j.insertStringInFile
(new File("c:\\FileToBeChanged.txt"));
}
catch (Exception e) {
e.printStackTrace();
}
}
public void insertStringInFile(File inFile)
throws Exception {
File outFile = new File("c:\\temp.txt");
FileInputStream fis = new FileInputStream(inFile);
BufferedReader in = new BufferedReader
(new InputStreamReader(fis));
FileOutputStream fos = new FileOutputStream(outFile);
PrintWriter out = new PrintWriter(fos);
String thisLine = "";
while ((thisLine = in.readLine()) != null) {
char[] arr=thisLine.toCharArray();
for (int i = 0; i < arr.length; i++) {
if(arr[i]=='"') arr[i]=''';
}
String s=new String(arr);
out.println(s);
}
out.flush();
out.close();
in.close();
inFile.delete();
outFile.renameTo(inFile);
}
}
Now run the second one to add echo's with each line.
- Code:
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
public class fileJava2 {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("C:\\fileToBeChanged.txt");
File file1=new File("C:\\temp.txt");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
FileOutputStream fos=new FileOutputStream(file1);
PrintWriter out = new PrintWriter(fos);
try {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
while (dis.available() != 0) {
out.println("echo(""+dis.readLine()+"");");
}
fis.close();
bis.close();
dis.close();
out.close();
file.delete();
file1.renameTo(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
fianally just add php tag and other functions as necessary.
Let me know if you find it helpful.
Re: 2 Very useful java class for web developing
nicely done
and thanks
However i am not going to give you rep++. because a non java php developer may find it scary to find the input and output file.
allow me, to give advice about making it even better.
My suggestion?
make the java files accept filenames via command line. Better, make a command line based instructiom (shell or batch) and when you drag the html file over the batch file, it will convert it automatically by the same file name with php extension.
Also, there can be option of making a gui
that can be expected from a talented one like you, right?
and thanks
However i am not going to give you rep++. because a non java php developer may find it scary to find the input and output file.
allow me, to give advice about making it even better.
My suggestion?
make the java files accept filenames via command line. Better, make a command line based instructiom (shell or batch) and when you drag the html file over the batch file, it will convert it automatically by the same file name with php extension.
Also, there can be option of making a gui
that can be expected from a talented one like you, right?
Re: 2 Very useful java class for web developing
Nice work Anik..
btw you can find some online converter to make life more easy. Here I can give you one of them,
http://www.quasarcr.com/html2php/
btw you can find some online converter to make life more easy. Here I can give you one of them,
http://www.quasarcr.com/html2php/
Similar topics
» About tomorrows Java class
» How To Set Environment(Class Path) variable permanently For JAVA And Tomcat Server
» Java Tutorial: Using Two Java Reference Keywords, this and super
» BIT 02: SE 206: Java extra class notice
» BIT 02: SE 206: java project progress report class
» How To Set Environment(Class Path) variable permanently For JAVA And Tomcat Server
» Java Tutorial: Using Two Java Reference Keywords, this and super
» BIT 02: SE 206: Java extra class notice
» BIT 02: SE 206: java project progress report class
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford