| | |
Help with my code.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
import java.io.BufferedReader;
import java.io.FileReader;
import TokenizerProcess.StringTokenizer;
import javax.swing.JOptionPane;
public class ReadFile {
public static int count = 0;
public static String[][]file = new String[6][3];
public void isReadFile(){
SubjectInput input = new SubjectInput();
try{
BufferedReader reader = new BufferedReader
(new FileReader("SubjectFiles/subjects.txt"));
String line;
while((line = reader.readLine())!=null){
StringTokenizer tokenFile = new StringTokenizer(line);
file[count][0] = tokenFile.nextToken();
file[count][1] = tokenFile.nextToken();
file[count][2] = tokenFile.nextToken();
count++;
}
}catch(Exception e){
JOptionPane.showMessageDialog(null,"File not found.");
}
}
public static void main (String args[]){
System.out.println(Readfile.file[1][1]);
}
}Hello, can someone help me, i dont know what is the problem with this. If i want to output the file[1][1], the output is "null". But if I will use the "sysout" at the isReadFile method, it will output the file[1][1]. I dont know what is the problem. Help. Thank you ahead.
Last edited by l_03; Jan 17th, 2009 at 9:36 pm.
Either make the String array as a member of
If all you need to do is to read the contents of the file once, there is no need to maintain static member variables or impart any state to the
ReadFile or make the method isReadFile static. Anyways, if your code looks the same way as you have posted, you are missing the invocation of isReadFile in main() which actually initializes the two dimensional String array.If all you need to do is to read the contents of the file once, there is no need to maintain static member variables or impart any state to the
ReadFile class; just make it a utility method and you should be good to go. I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Why won't this code work? (VB.NET)
- Need help with DirectX code (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the Java Forum
- Previous Thread: Help with managing .dat files
- Next Thread: Long cannot be dereferenced?
| Thread Tools | Search this Thread |
Tag cloud for Java
android api appinventor apple applet application arc arguments array arrays automation binary bluetooth c++ chat class classes client code codesnippet compiler component csv database doctype draw ebook eclipse error event exception fractal freeze game givemetehcodez graphics gui html ide image input integer intellij iphone j2me java java.xls javaprojects jni jpanel julia linux list login loop loops mac map method methods mobile netbeans newbie number online oracle page parameter print problem program programming project recursion reporting rotatetext scanner screen server set size sms socket sort sourcelabs sql string superclass swing system template test testautomation threads time title tree tutorial-sample windows working






