Results 1 to 8 of 8
  1. #1
    skj
    skj is offline Member
    Join Date
    Oct 2014
    Posts
    20
    Rep Power
    0

    Default read from file input

    The program is reading from file input. how can I replace hate with love
    the file contains only one line
    I hate programing!




    Java Code:
    [import java.util.Scanner;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    
    public class Program3 {
    	public static void main(String[] args) {
    		Scanner fileIn = null;
    
    		try {
    			fileIn = new Scanner(new FileInputStream(
    					"C://Users//skalem//Desktop//program3.txt"));
    
    		}
    
    		catch (FileNotFoundException e) {
    
    			System.out.println("File not ound");
    			System.exit(0);
    
    		}
    
    		String sentence = fileIn.next() + " " + fileIn.next() + " "
    				+ fileIn.next();
    
    		System.out.println(sentence);
    		
    		
    		
    		
    	}
    output
    I hate programming!]
    Last edited by skj; 10-25-2014 at 08:38 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: read from file input

    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 response, don't ignore it, ask a question.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: read from file input

    Quote Originally Posted by skj View Post
    I hate programing!
    [ ... ]
    I hate programming!
    If you really do, change your study, because you won't be a happy person as you are now.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    skj
    skj is offline Member
    Join Date
    Oct 2014
    Posts
    20
    Rep Power
    0

    Default Re: read from file input

    This is the program that I am supposed to write
    my out put supposed to be I hate programing ! and then I have to add some codes to replace hate to love
    Thank you for your advice ,but I do like programing :)

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: read from file input

    how can I replace hate with love
    See the String class. It has several useful methods.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    skj
    skj is offline Member
    Join Date
    Oct 2014
    Posts
    20
    Rep Power
    0

    Default Re: read from file input

    I am trying to reply using "Go advance" option to wrap my new program ,but the option is not working it says address not found

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: read from file input

    Sounds like a bug in the forum's software.

    I just tried it and it works for me, no problem.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: read from file input

    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Mac: Can't read input file, when adding pictures to a JFrame
    By swedishfished in forum New To Java
    Replies: 4
    Last Post: 08-27-2014, 03:42 AM
  2. Replies: 10
    Last Post: 04-01-2013, 02:50 PM
  3. read input file into array
    By randoms:) in forum New To Java
    Replies: 3
    Last Post: 04-23-2011, 09:52 AM
  4. read only double input from text file
    By napi1234 in forum New To Java
    Replies: 6
    Last Post: 06-28-2010, 05:06 PM
  5. read a specific line in an input file
    By sara12345 in forum Advanced Java
    Replies: 7
    Last Post: 01-03-2010, 11:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •