SRL Archive - General

JAVA project university related


onilika

2014-06-01 06:08:48

Hello, so I need to do a project for university and I'm having doubts doing some stuff. I still haven't started like I should, and I only have 2 weeks left.
I have those modifiers and selectors methods, but I can't find a way to use them, since I'm reading a text file to obtain information.
I don't know how to use those methods, when we are obtaining information from a text file, and when the user is writing it directly through the console.
Yes, I do need help, and I was hopping someone could add me to help me out with this.

sincerely, Aquilino

masterBB

2014-06-01 07:42:42

I don't completly understand your question. Might be a combination of rusty java and bad english from me though ;).

Did you meant accessor methods instead of selectors? And mutator methods instead of modifiers?(these are often called the same). I googled selectors but that is an object for tracking read/write events in one thread. Sounds strange to use in the same sentence as modifiers methods.

Tbh I don't understand what the program does at all. "Obtaining information from a text file" " writing through the console"

Could you add more information?

J J

2014-06-01 08:16:56

Yes we need more information or code examples. Right now it makes no sense to me either.

[XoL]

2014-06-01 14:39:56

Do you mean likeee if the user types something in, the program records the information into a variable?
If thats the case you can do it very very easily, and even have constructors through the means of empty variables.

For example
Int a = 0;

Scanner keyboard = new Scanner (System.in);
System.out.println("Type your favorite number");
a = keyboard.nextInt;

System.out.println("Your favorite number is" + a );

I actually have no idea what you need help with so all this information is very generic.
Try reading this code, its what I use almost every time I want to implement reading from a text file


import java.io.*;

public class ReadFile {

public static void main(String[] args){
String string="";
String file ="textFile.txt";

//reading
try{
InputStream ips=new FileInputStream(fichier);
InputStreamReader ipsr=new InputStreamReader(ips);
BufferedReader br=new BufferedReader(ipsr);
String line;
while ((ligne=br.readLine())!=null){
System.out.println(line);
string+=line+"\n";
}
br.close();
}
catch (Exception e){
System.out.println(e.toString());
}

//writing
try {
FileWriter fw = new FileWriter (file);
BufferedWriter bw = new BufferedWriter (fw);
PrintWriter fileOut = new PrintWriter (bw);
fileOut.println (string+"\n test of read and write !!");
fileOut.close();
System.out.println("the file " + file + " is created!");
}
catch (Exception e){
System.out.println(e.toString());
}
}
}

masterBB

2014-06-01 14:41:51

Me and onilika are working on it. Thanks for the help though xol ;)

[XoL]

2014-06-01 14:46:46

Oh ok sweet, good luck guys!