6 Replies - 1354 Views - Last Post: 21 December 2010 - 02:22 PM Rate Topic: -----

#1 Mokgar  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 113
  • Joined: 21-December 10

How can i make java write to a file and read off that file...

Posted 21 December 2010 - 12:33 PM

I'm new to java and I'm creating a simple plug-in for a game and basically I'm stuck on this one part, I need this program to write a characters name to a file when and admin types something in-game and also, does this basically:

//Check if player is in the group nonpvp
		if (player b ==(this is where it needs to check if the player is on the list in this file and if they are return true)


Help is appreciated, thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: How can i make java write to a file and read off that file...

#2 Scottm  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 42
  • View blog
  • Posts: 238
  • Joined: 11-February 10

Re: How can i make java write to a file and read off that file...

Posted 21 December 2010 - 01:07 PM

Try reading this!
Was This Post Helpful? 0
  • +
  • -

#3 Mokgar  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 113
  • Joined: 21-December 10

Re: How can i make java write to a file and read off that file...

Posted 21 December 2010 - 01:11 PM

View PostScottm, on 21 December 2010 - 12:07 PM, said:

Try reading this!


thank you soo much ive been refreshing this page since i made it as i really want to accomplish this! i looked but i couldnt find this so thanyou very much~!
Was This Post Helpful? 0
  • +
  • -

#4 Scottm  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 42
  • View blog
  • Posts: 238
  • Joined: 11-February 10

Re: How can i make java write to a file and read off that file...

Posted 21 December 2010 - 01:19 PM

No problem! You can also use the search function (located in the top right of your page, right under the banner), and after you search, you can limit it down to tutorials!

Hope you find your answer.

This post has been edited by Scottm: 21 December 2010 - 01:20 PM

Was This Post Helpful? 0
  • +
  • -

#5 Mokgar  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 113
  • Joined: 21-December 10

Re: How can i make java write to a file and read off that file...

Posted 21 December 2010 - 01:38 PM

View PostScottm, on 21 December 2010 - 12:19 PM, said:

No problem! You can also use the search function (located in the top right of your page, right under the banner), and after you search, you can limit it down to tutorials!

Hope you find your answer.


i still cant find out how to make the plugin search to see if player b is on the list that it is reading, in my code player b has been given a string i need the program to see if this string matches with any of of the names on the list and if it does return true. ive tried searching ive found nothing D:
Was This Post Helpful? 0
  • +
  • -

#6 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: How can i make java write to a file and read off that file...

Posted 21 December 2010 - 02:11 PM

You could always use an ArrayList<String> and read in the names from the file (from the tutorial) and read them into the ArrayList. From there, just call the contains() method.
Was This Post Helpful? 0
  • +
  • -

#7 Mokgar  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 113
  • Joined: 21-December 10

Re: How can i make java write to a file and read off that file...

Posted 21 December 2010 - 02:22 PM

View PostDogstopper, on 21 December 2010 - 01:11 PM, said:

You could always use an ArrayList<String> and read in the names from the file (from the tutorial) and read them into the ArrayList. From there, just call the contains() method.

so i could do:

import java.io.*;

 

public class File {

    BufferedReader in;

    String read;

  

    public File(){

        if {

            //open a bufferedReader to file helloworld.txt

            in = new BufferedReader(new FileReader("helloworld.txt"));

 

            //read a line from helloworld.txt and save into a string

            read = in.contains(player B)/>;

 

            //print out the line

            System.out.println("file output: " + read);

 

            //safely close the BufferedReader after use

            in.close();

        }catch(IOException e){

            System.out.println("There was a problem:" + e);

        }

    }

 

    public static void main(String[] args){

        File File = new File();

    }

}




and player b will be defined earlier on is that what you said I should do, I'm sorry if I'm being stupid in don't know much but I'm learning and I learn quickest from doing projects like this, :P

This post has been edited by Mokgar: 21 December 2010 - 02:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1