Skip to content

Instantly share code, notes, and snippets.

@theabhayprajapati
Created September 6, 2022 14:28
Show Gist options
  • Save theabhayprajapati/a79ff8050507d22956ff364e0b6c41a6 to your computer and use it in GitHub Desktop.
Save theabhayprajapati/a79ff8050507d22956ff364e0b6c41a6 to your computer and use it in GitHub Desktop.
CODE THAT HELPED ME TO MAKE THE COMPANIES.MD FILE GIST Written in Java.
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
/*read lines from fle adn conver in tor array*/
String[] lines = new String[0];
String path = "D:\\learn\\Data Structures and Algorithms\\untitled\\src\\Trees\\sde1.txt";
try {
lines = Files.readAllLines(Paths.get(path)).toArray(new String[0]);
} catch (IOException e) {
e.printStackTrace();
}
/*loop and print*/
for (String line : lines) {
System.out.println(line);
}
/*make markdown page with list style*/
String md = "sde.md";
StringBuilder markdown = new StringBuilder();
int rank = 1;
for (String line : lines) {
/*create a new line*/
/*“\r\n”*/
/*create and with ending .com and */
markdown.append(rank).append(". ").append("[").append(line).append("](").append("https://").append(line.replace(" ", "")).append(".com").append(")").append(" ");
/*for links if space is there the remove it*/
markdown.append("\r\n");
rank++;
}
System.out.println(markdown);
try {
/*if file is there then delete it*/
Files.deleteIfExists(Paths.get(md));
Files.write(Paths.get(md), markdown.toString().getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment