• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java.io.File  RSS feed

 
Derek Kuether
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble using the File object. It seems like it doesnt even exist. From what I understand it is supposed to exist in java.io. Am I missing something?


package compute;
import java.io.*;

/**
*
* @author Derek
*/
public class Compute {

/**
* @param args the command line arguments
*/
public static void main(File javatest) {
FileReader(javatest);
}
}
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think it's unable to find the File class? Is there an error message or something that indicates that is the problem?

I do see a couple other problems, unrelated to File. One is with "FileReader(javatest)" - I think you're trying to construct a new instance here, using a constructor. To do this, you would need a new keyword. Also, your main method will not be identified as the starting point of the application unless it matches the standard signature of a main method: "public static void main(String[] args)". You can replace "[]" with "...", and you can replace "args" with any other valid java identifier. But the rest needs to be unchanged.
 
Derek Kuether
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made the changes I think you were talking about but FileReader still isnt "found". Also, String wouldnt make sense to use. Can I not use any other object type?
the error reads "Cannot find symbol". For both File and FileReader.
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Derek Kuether wrote:I made the changes I think you were talking about but FileReader still isnt "found".


could you please show us the whole code. so that we can help it out on the base of that. and do use "code" tag for better readability..

thanks
 
Derek Kuether
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Needless to say, I dont really know what Im doing. By code tagging, do you mean commenting out? I just started so this is the whole code:

package compute;
import java.io.*;

/**
*
* @author Derek
*/
public class Compute {

/**
* @param args the command line arguments
*/
public static void main(File javatest) {
FileReader txt;
txt = new FileReader(javatest);
}
}
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Derek Kuether wrote: . . . By code tagging, do you mean commenting out?
No, it means what it says here, and it would have made you post look like this:-
I just started so this is the whole code:


You have done something wrong there; the intent of the main method is only to start the application off. Everything else should be elsewhere in your code. By changing the signature of the method, you will neither get the FileReader working, nor start your app.
As for FileReaders, have a look in the Java Tutorials, where you will find an example wrapping one in a BufferedReader, which is usually the best way to use a file reader.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!