Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualCuajin

Posted 05 April 2012 - 05:56 AM

I am trying to read the inventory for a game in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5

I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1 int. The ints are the stats of the item.

Scanner read = new Scanner(new File("inventory.txt")) ;
while (read.hasNext())
{
	infile.findInLine("Shield") ;
}

Please, help me.

#4Cuajin

Posted 05 April 2012 - 05:55 AM

I am trying to read the inventory for a game in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5

I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1.

Scanner read = new Scanner(new File("inventory.txt")) ;
while (read.hasNext())
{
    infile.findInLine("Shield") ;
}

Please, help me.

#3Cuajin

Posted 05 April 2012 - 05:54 AM

I am trying to read the inventory for a game in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5

I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1.

Scanner read = new Scanner(new File("inventory.txt")) ;
while (read.hasNext())
{
infile.findInLine("Shield") ;
 
}

Please, how do I do this?

#2Cuajin

Posted 05 April 2012 - 05:54 AM

I am trying to read the inventory for a game in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5

I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1.

Scanner read = new Scanner(new File("inventory.txt")) ;
infile.findInLine("Shield") ;

Please, how do I do this?

#1Cuajin

Posted 05 April 2012 - 05:53 AM

I am trying to read the inventory for a game in a saved in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5

I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1.

Scanner read = new Scanner(new File("inventory.txt")) ;
infile.findInLine("Shield") ;

Please, how do I do this?

PARTNERS