This site requires JavaScript, please enable it in your browser!
Greenfoot back
Belinus
Belinus wrote ...

2021/1/5

Create Map from a file

Belinus Belinus

2021/1/5

#
Hi, i have the problem that i want to create a map from a file. I got no problems with saving the file, but i dont know who to continue. I want to read the file(its just 1 and 0)and if it is "1", he should do something.
String z="";
try
{
BufferedReader comp = new BufferedReader(new FileReader("SaveEdit1.txt"));
z=comp.readLine();
System.out.println(z);
if(z=="1")
                         {
                             Block block = new 
                            Block(0,0,false);
                             addObject(block,  22+x*35, 
                             20+y*20);
                             Edit1Levblo++;
                            }
}
catch(IOException e)
                {
                    System.out.println("Something went 
                    wrong");
                }
With the System.out.println() i get the right number(the number that i saved in the file) but he dont creates the object. How can I do an If(fileText=="1")?? P.S. Sorry for bad English
Belinus Belinus

2021/1/5

#
Ok, got the Problem. I had to use
String z="";
String one="1";
try
{
BufferedReader comp = new BufferedReader(new FileReader("SaveEdit1.txt"));
z=comp.readLine();
System.out.println(z);
if(z.equals(one))
                         {
                             Block block = new
                            Block(0,0,false);
                             addObject(block,  22+x*35, 
                             20+y*20);
                             Edit1Levblo++;
                            }
}
catch(IOException e)
                {
                    System.out.println("Something went 
                    wrong");
                }
danpost danpost

2021/1/5

#
Remove line 2 and change line 8 to this:
if ("1".equals(z))
Belinus Belinus

2021/1/5

#
ok thanks
You need to login to post a reply.