Комментарии:
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
// HTML stands for "Hyper Text Markup Language"
// used for creating web pages
// 1. ask user for a file name
// 2. check if file exists
// 3. rename .txt as .html
// 4. determine if file is empty
// 5. read each line and insert necessary <tags>
Scanner scanner = new Scanner(System.in);
Scanner fileIn; //input file connection
PrintWriter fileOut; //HTML file connection
String filenameIn; //original file's name
String filenameOut; //new HTML file's name
int dotIndex; //position of . in filename
String line = null; // a line from the input file
// 1. ask user for a file name (or file path)
System.out.println("Enter file name or path");
filenameIn = scanner.nextLine();
// 2. check if file exists
try {
//3. rename .txt as .html
fileIn = new Scanner(new FileReader(filenameIn));
dotIndex = filenameIn.lastIndexOf(".");
if(dotIndex == -1) {
filenameOut = filenameIn + ".html";
}
else {
filenameOut = filenameIn.substring(0,dotIndex) + ".html";
}
fileOut = new PrintWriter(filenameOut);
// 4. determine if file is empty
try {
line = fileIn.nextLine();
}
catch(NoSuchElementException e) {
System.out.println("Error: "+e.getMessage());
}
if(line==null) {
System.out.println("This file is empty :(");
}
else {
// 5. read each line and insert necessary <tags>
fileOut.println("<html>");
fileOut.println("<head>");
fileOut.println("</head>");
fileOut.println("<body>");
fileOut.println(line);
while(fileIn.hasNextLine()) {
fileOut.println("<br>");
line = fileIn.nextLine();
if(line.isEmpty()) {
fileOut.println("<br>");
}
else {
fileOut.println(line);
}
}
fileOut.println("</body>");
fileOut.println("</html>");
System.out.println("HTML file is processed :)");
}
fileIn.close();
fileOut.close();
}
catch(FileNotFoundException e) {
System.out.println("File not found");
}
}
}
Hey bro. you are my teacher.... I would like to know as much as you do in java programming. I wonder how is the education in the united states. In ecuador, it is not that good.
Ответитьseriously your the best!
keep it up
Very interesting!!
ОтветитьCan python ide be used to create this
Ответитьthank you
ОтветитьSuperbe...well done ❤
ОтветитьBrilliant Presentation 💯
ОтветитьI refreshed but the .html file didn't pop up...
ОтветитьYour the type of coder that makes coding fun! 😊
ОтветитьHI! so am I able to upload an entire java program like this? for example if I built a game that used multiple java files, would I be able to upload them all to a website and have my program run on there?
ОтветитьWhich editor are you using broo???
ОтветитьLove you Bro :)
ОтветитьFor some reason, it always says "File not found" even after I copied your code, the error is the same.
ОтветитьWhy don't just write html?
ОтветитьGreat presentation!
ОтветитьThank your god you are here!!!
ОтветитьExclent
ОтветитьBro thanks for this videos ☺️i have created by watching your videos
Ответитьhu
Ответитьsuper
ОтветитьCan we make it using other IDEs like IntelliJ and NetBeans?
ОтветитьThanks bro :)
ОтветитьThis is underrated
Ответитьgreat tutorial!!
Ответить🌸God bless you🌸🤍🌸
ОтветитьThanks 😊 🙏
ОтветитьI've been watching your videos for the past 2 or 3 weeks now and I can't believe that your videos get so little attention. You deserve 100x the attention on this platform :)
ОтветитьThis demo is very good, but there are too many code. If we use dom4j , we can use only 5 lines code to read any HTML or xml or anything else.
ОтветитьPeople NEED to see these tutorials
Ответить♡
ОтветитьPeople are really missing out on these tutorials.
Ответить