Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Need help with ideas

  1. #1
    Junior Member
    Join Date
    Jan 2019
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with ideas

    when I give input in my text file as

    title: just do it
    _something_

    I should get my output in the java console in the html format as follows:

    <title>just do it </title>
    <i>something<i/>italicized line

    Please help me how to do it pleaseeeeeeeeeeeeeeeeee.Note :Output is expected in the java console

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,795
    Thanks
    52
    Thanked 2,329 Times in 2,285 Posts

    Default Re: Need help with ideas

    What have you tried?
    Be sure to wrap all posted code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2019
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with ideas

    hello,

    I have created an array list and stored the contents of the file in the Array list.

    I just need a clue on the following:

    if suppose the contents of the array list has *something*.The output in java console should be <b>something</b>

    if it has %hello% it should be underline like <u>underline</u>

    basically depending the on the special characters the output in the java console should be in HTML format. Please help

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,795
    Thanks
    52
    Thanked 2,329 Times in 2,285 Posts

    Default Re: Need help with ideas

    Can you post the code that shows what you have tried?
    Be sure to wrap all posted code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2019
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with ideas

    Hi, I have attached the file. Could you please check
    Attached Files Attached Files

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,795
    Thanks
    52
    Thanked 2,329 Times in 2,285 Posts

    Default Re: Need help with ideas

    Please post the code here, with code tags. Not as an attachment.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2019
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with ideas

    import java.io.*;
    import java.util.ArrayList;
    import java.util.Stack;
    public class hello_world2
    {
    public static void main(String[] args)throws Exception
    {


    String strin = "";
    /*creates a file as filename and passing the text file as input
    *
    */
    File file = new File("filename.txt");

    /*
    * Initialize Arraylist
    */
    ArrayList<String> StoreFileElements = new ArrayList<String>();

    /*
    * Intialize Stack Array
    *
    */
    Stack<String> s1 = new Stack<String>();

    /*
    * Reads the file name and prints the content of text file as output
    *
    */
    try
    {
    /*
    * Buffer reader used to read the contents of the filename.txt
    */
    BufferedReader br = new BufferedReader(new FileReader(file));
    /*
    * if clause created to check if the file name is empty or not.If it is not empty data of the file will be captured in an ArrayList
    */
    if(new File("filename.txt").length() > 0)

    {
    /*Capturing the data of the file in an array list
    *
    */
    while ((strin = br.readLine()) != null)


    StoreFileElements .add(strin);

    System.out.println("<html>");
    /*
    * for loop is created to eliminate the unwanted brackets in the output file
    */
    for (int x= 0; x < StoreFileElements.size(); x++)
    System.out.println(StoreFileElements.get(x));



    System.out.println("</html>");





    }

    else {
    System.out.println("");
    }
    }

    catch(FileNotFoundException c)

    {
    System.out.println("File not found");
    }
    }

    private static char[] get(int x) {
    // TODO Auto-generated method stub
    return null;
    }

    }

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,795
    Thanks
    52
    Thanked 2,329 Times in 2,285 Posts

    Default Re: Need help with ideas

    What happens when the code is compiled and executed?
    What is the program's output?
    What needs to be changed?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Jan 2019
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with ideas

     
     
    import java.io.*;
    import java.util.ArrayList;
    import java.util.Stack; 
    	public class hello_world2
    	{ 
    	  public static void main(String[] args)throws Exception 
    	  { 
     
     
    		 String strin = "";
    		  /*creates a file  as filename and passing the text file as input
    		   * 
    		   */	  
    	  File file = new File("filename.txt"); 
     
    	/*
    	 * Initialize Arraylist
    	 */
    	  ArrayList<String> StoreFileElements = new ArrayList<String>();
     
    	  /*
    	   * Intialize Stack Array
    	   *
    	   */
    	  Stack<String> s1 = new Stack<String>();
     
    	  /*
    	   * Reads the file name and prints the content of text file as output
    	   * 
    	   */
    	  try
    	  {
    		  /*
    		   * Buffer reader used to read the contents of the filename.txt
    		   */
    	  BufferedReader br = new BufferedReader(new FileReader(file)); 
    	  /*
    	   * if clause created to check if the file name is empty or not.If it is not empty data of the file will be captured in an ArrayList
    	   */
    	  if(new File("filename.txt").length() > 0)
     
    	  {
    	/*Capturing the data of the file in an array list
    	 * 
    	 */
    	  while ((strin = br.readLine()) != null)
     
     
    		  StoreFileElements .add(strin);
     
    	   System.out.println("<html>");
    	  /*
    	   * for loop is created to eliminate the unwanted brackets in the output file
    	   */
    	  for (int x= 0; x < StoreFileElements.size(); x++)
    		  System.out.println(StoreFileElements.get(x));
     
     
     
    	    System.out.println("</html>");
     
     
     
     
     
    	  }
     
    	  else  {
    		  System.out.println("");
    	  }
    	  }
     
    	  catch(FileNotFoundException c)
     
    	  {
    	    System.out.println("File not found");
    }
    }

    private static char[] get(int x) {
    // TODO Auto-generated method stub
    return null;
    }

    }
    [/CODE]

    --- Update ---

     
     
    import java.io.*;
    import java.util.ArrayList;
    import java.util.Stack; 
    	public class hello_world2
    	{ 
    	  public static void main(String[] args)throws Exception 
    	  { 
     
     
    		 String strin = "";
    		  /*creates a file  as filename and passing the text file as input
    		   * 
    		   */	  
    	  File file = new File("filename.txt"); 
     
    	/*
    	 * Initialize Arraylist
    	 */
    	  ArrayList<String> StoreFileElements = new ArrayList<String>();
     
    	  /*
    	   * Intialize Stack Array
    	   *
    	   */
    	  Stack<String> s1 = new Stack<String>();
     
    	  /*
    	   * Reads the file name and prints the content of text file as output
    	   * 
    	   */
    	  try
    	  {
    		  /*
    		   * Buffer reader used to read the contents of the filename.txt
    		   */
    	  BufferedReader br = new BufferedReader(new FileReader(file)); 
    	  /*
    	   * if clause created to check if the file name is empty or not.If it is not empty data of the file will be captured in an ArrayList
    	   */
    	  if(new File("filename.txt").length() > 0)
     
    	  {
    	/*Capturing the data of the file in an array list
    	 * 
    	 */
    	  while ((strin = br.readLine()) != null)
     
     
    		  StoreFileElements .add(strin);
     
    	   System.out.println("<html>");
    	  /*
    	   * for loop is created to eliminate the unwanted brackets in the output file
    	   */
    	  for (int x= 0; x < StoreFileElements.size(); x++)
    		  System.out.println(StoreFileElements.get(x));
     
     
     
    	    System.out.println("</html>");
     
     
     
     
     
    	  }
     
    	  else  {
    		  System.out.println("");
    	  }
    	  }
     
    	  catch(FileNotFoundException c)
     
    	  {
    	    System.out.println("File not found");
    	  }
    	  }
     
    	private static char[] get(int x) {
    		// TODO Auto-generated method stub
    		return null;
    	}
     
    	  }

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,795
    Thanks
    52
    Thanked 2,329 Times in 2,285 Posts

    Default Re: Need help with ideas

    What happens when the code is compiled and executed?
    What is the program's output?
    What needs to be changed?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Jan 2019
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with ideas

    sorry I posted the code twice.

    The output of the code is: whatever I store in the file gets displayed:
    <html>
    title: Hello
    I *am* fine
    __Hi_
    be !bold
    </html>

    what i need to do is or need help is:
    I need to replace the special characters with the html tags for example:
    <html>
    <head>
    <title>hello<title>
    </head>
    I<b>am</b>fine
    <i>hi</i>
    </html>
    Please let me know if i was clear

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,795
    Thanks
    52
    Thanked 2,329 Times in 2,285 Posts

    Default Re: Need help with ideas

    Work on the problem one step at a time.
    It currently outputs <html> and </html>

    What needs to be done with the first line that is read?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Jan 2019
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with ideas

    yes if your file is empty, the output is just the HTML tags:
    when the first line starts with the "title:", then the text following "title:" should be enclosed between <title><title>

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,795
    Thanks
    52
    Thanked 2,329 Times in 2,285 Posts

    Default Re: Need help with ideas

    when the first line starts with the "title:", then the text following "title:" should be enclosed between <title><title>
    Ok design the code to do that. Look at the String class for useful methods.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help me with ideas
    By kickass in forum Java Theory & Questions
    Replies: 2
    Last Post: August 29th, 2014, 07:08 AM
  2. NEED HELP WITH IDEAS
    By ash12 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 21st, 2012, 05:52 PM
  3. Any ideas?
    By ahender1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 2nd, 2012, 03:58 PM
  4. Any Program Ideas?
    By Java Programmer in forum Java Theory & Questions
    Replies: 7
    Last Post: January 18th, 2012, 08:05 AM

Tags for this Thread