Java generate a website

Java generate a website

Bro Code

4 года назад

71,127 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Bro Code
Bro Code - 24.06.2020 15:02

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");
}

}
}

Ответить
Christian Rodriguez
Christian Rodriguez - 08.11.2023 06:34

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.

Ответить
BlazingNoob
BlazingNoob - 26.09.2023 20:04

seriously your the best!
keep it up

Ответить
LiarleyEV
LiarleyEV - 26.09.2023 06:29

Very interesting!!

Ответить
Ali Layaan
Ali Layaan - 17.07.2023 08:26

Can python ide be used to create this

Ответить
GoodGameDev
GoodGameDev - 13.07.2023 16:41

thank you

Ответить
Akeem_B
Akeem_B - 05.06.2023 23:00

Superbe...well done ❤

Ответить
Kingsley Ohene
Kingsley Ohene - 23.05.2023 02:42

Brilliant Presentation 💯

Ответить
The Champ Draws
The Champ Draws - 07.05.2023 23:57

I refreshed but the .html file didn't pop up...

Ответить
Xayles
Xayles - 25.04.2023 23:49

Your the type of coder that makes coding fun! 😊

Ответить
Craig Benjamin
Craig Benjamin - 07.03.2023 07:18

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?

Ответить
HARISH
HARISH - 17.11.2022 16:56

Which editor are you using broo???

Ответить
Atikur Rahman
Atikur Rahman - 03.09.2022 05:03

Love you Bro :)

Ответить
B 48 MFJ RC CARS PARTS AND HOW TO BUILD THEM
B 48 MFJ RC CARS PARTS AND HOW TO BUILD THEM - 03.07.2022 15:23

For some reason, it always says "File not found" even after I copied your code, the error is the same.

Ответить
zqlimy
zqlimy - 05.05.2022 20:04

Why don't just write html?

Ответить
David Gabbay
David Gabbay - 24.04.2022 01:17

Great presentation!

Ответить
Dave Mena
Dave Mena - 24.03.2022 19:34

Thank your god you are here!!!

Ответить
Titan Wala 2.O
Titan Wala 2.O - 28.10.2021 17:24

Exclent

Ответить
PRABUDDHA Pal
PRABUDDHA Pal - 13.10.2021 15:45

Bro thanks for this videos ☺️i have created by watching your videos

Ответить
Trương Khánh
Trương Khánh - 18.09.2021 13:57

hu

Ответить
SAI SREEKAR SUNKU
SAI SREEKAR SUNKU - 16.08.2021 13:14

super

Ответить
Arsh Mandal
Arsh Mandal - 08.05.2021 19:27

Can we make it using other IDEs like IntelliJ and NetBeans?

Ответить
Augis, Chadie Gil S.
Augis, Chadie Gil S. - 11.01.2021 09:42

Thanks bro :)

Ответить
YourAllTrash
YourAllTrash - 16.11.2020 19:24

This is underrated

Ответить
Vincent Choo
Vincent Choo - 13.10.2020 02:03

great tutorial!!

Ответить
Nehal Ayaaz
Nehal Ayaaz - 08.07.2020 19:45

🌸God bless you🌸🤍🌸

Ответить
Nehal Ayaaz
Nehal Ayaaz - 08.07.2020 19:39

Thanks 😊 🙏

Ответить
Dygit
Dygit - 03.07.2020 20:21

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 :)

Ответить
girl中国
girl中国 - 25.06.2020 18:46

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.

Ответить
Nathan Lloyd
Nathan Lloyd - 25.06.2020 10:08

People NEED to see these tutorials

Ответить
M O
M O - 24.06.2020 21:57

Ответить
RipperRoo92
RipperRoo92 - 24.06.2020 11:19

People are really missing out on these tutorials.

Ответить