Vinski's Profile User Rating: -----

Reputation: 9 Worker
Group:
Members
Active Posts:
19 (0.03 per day)
Joined:
29-September 12
Profile Views:
461
Last Active:
User is offline Mar 08 2014 10:47 PM
Currently:
Offline

Previous Fields

Country:
HR
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   Vinski is back with a lot of Java knowledge. (7.3.2014)

Posts I've Made

  1. In Topic: Failing To Render Only Visible Tiles in Large Tile Map

    Posted 8 Mar 2014

    Never mind. Fixed this.
  2. In Topic: Unable to write user generated input to a text file

    Posted 8 Mar 2014

    Hello, Mash67.

    You need to change String curLine = keyboard.nextLine(); to String curLine = keyboard.next();. That way it worked for me.

    EDIT: Also change textOut.write(keyboard.nextLine()); to textOut.write(keyboard.next());.

    So the complete code would be:
    public static void main(String[] args) 
        {
            Scanner keyboard = new Scanner(System.in);
            System.out.print("Enter the file name: ");
            String fileName = keyboard.nextLine();
            System.out.print("Choose binary or text file (b/t): ");
            char fileType = keyboard.next().trim().charAt(0);
            System.out.print("Choose read or write (r/w): ");
            char actionType = keyboard.next().trim().charAt(0);
            System.out.println("Enter a line of information to write to the file: ");
            String curLine = keyboard.next(); // <-- This has been changed.
            
            try
            {
                BufferedWriter textOut = new BufferedWriter(new FileWriter(fileName + ".txt"));
    
                textOut.write(curLine);
    
                System.out.println("Would you like to enter another line? (Y/N only)");
                char proceed = keyboard.next().trim().charAt(0);
    
                while (proceed == 'Y' || proceed == 'y')
                {
                    System.out.println("Enter a line of information to write to the file: ");
                    textOut.write(keyboard.next()); // <-- This has been changed.
                    System.out.println("Would you like to enter another line? (Y/N only)");
                    proceed = keyboard.next().trim().charAt(0);
                }
                textOut.close();
            }
            catch (FileNotFoundException e)
            {
                System.out.println("Error opening the file \"" + fileName + "\".");
                System.exit(0);
            }
            catch (IOException e)
            {
                System.out.println("Problem with output.");
                System.exit(0);
            }
        }
    
    
  3. In Topic: call method

    Posted 8 Mar 2014

    Help me understand your question -- you have to create a class with main method that will call a method named cat().
    After that, you need to programatically take the code from the cat() method and put it in the new file so that you can
    compiles the new file? I'm a litle bit confused.


    EDIT: I think I got it!

    When you want to catch an exception, you use try and then catch(some exception here). So this would be the correct code:
    	public static void cat(File file){
    		Scanner input = null;
    		String line = null;
    		
    		try{
    			input = new Scanner(file);
    		}catch(Exception e){
    			e.printStackTrace();
    		}finally{
    			if(input != null){
    				input.close();
    			}
    		}
    	}
    
    
  4. In Topic: shopping cart for GUI applications

    Posted 10 Nov 2013

    Starting with database could be a little too advanced for a beginner.

    Therefore I would recommend to look into Java I/O.

    You could make it as each line is one record. For example, each record has
    an ID, Name and Quantity. You could use a slash ('/') as a data separator.
    So when you get your records, you go through the array and then just get the
    data of a record by splitting the line into three parts (in this example).

    Hopefully that made sense.

    If the software you're trying to create includes private information such as
    passwords, I would recommend you to look into encryption unless you plan to
    do it as a personal project (a.k.a. not publish it):
    Link #1
    Link #2

    A little bit over a year ago, I made an address book using the same method I
    explained above. I would've provided you with the source code, but I've lost it.
  5. In Topic: Problem translating image processing algorithm into code

    Posted 1 Oct 2012

    You're welcome.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
July 6
Gender:
Location:
Croatia
Years Programming:
3
Programming Languages:
QBasic
Visual Basic
Java

Contact Information

E-mail:
Private

Friends

Comments

Vinski has no profile comments yet. Why not say hello?