• 0

[Java] reading file


Question

i m tryin to learn java need little help

i have data in this format

46728 s 1000 2700

87324 c 1500 7689

79873 s 1000 800

89832 c 2000 3000

98322 c 1000 750

public void process() {  
		FileInputStream in;
		 DataInputStream input;
		int acc_no;
		char type;
		double min_bal;
		double curr_bal;


		  try{
			  in = new FileInputStream("Dat.txt");
			  input = new DataInputStream(in);
		  } catch (IOException e) 
		  {
			  System.out.print("Filen't exists");
			  System.exit(0);
		  }	  

		  try{			  
			  acc_no = input.readInt();
			  type = input.readChar();
			  min_bal = input.readDouble();
			  curr_bal = input.readDouble();
			  System.out.print('\n			  System.out.print(acc_no);
			  System.out.print('\t			  System.out.print(type);
			  System.out.print('\t			  System.out.print(min_bal);
			  System.out.print('\t			  System.out.print(curr_bal);  
		  }catch(EOFException eofex)
		  {
			  try{
				  input.close();
			  }catch (IOException ioe)
			  {
				  System.out.print("Fileclosed");
			  }
		  }
		  catch(IOException e)
		  {
			  System.out.print("Errorng reading file DATA.txt");
		  }

I just want to read and print the data :( but this giving me wrong output. and if i use input.readline and store whole line in string then it it prints right data i want data in int,char,double,double variables. i wil read data in whileloop line by line but atleast it shuld print first line right :(

Link to comment
https://www.neowin.net/forum/topic/460574-java-reading-file/
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Ok I have done every thing :) everything working fine. just one problem

I made it using Jbuilder. so if i run it in Jbuilder its running fine no error and giving required results but if i go to command prompt and type java bank.java

it gives error

Exception in thread "main" java.lang.NoClassDefFoundError: E:\WORK\java\

bank/java

what is this exceptiong :/ it only appear if i run using java command in windows

  • 0
  Umair_Ahmad_Khan said:

Ok I have done every thing :) everything working fine. just one problem

I made it using Jbuilder. so if i run it in Jbuilder its running fine no error and giving required results but if i go to command prompt and type java bank.java

it gives error

Exception in thread "main" java.lang.NoClassDefFoundError: E:\WORK\java\

bank/java

what is this exceptiong :/ it only appear if i run using java command in windows

.java files are your source program. At run time you need the .class file.

Your best approach is to use JBuilder to make an executable .jar containing all your classes that you need for your app (see the JBuilder help & examples for step-by-step instructions) then run it with

java -jar myAppName.jar or by simply double-clicking it

Edited by JamesCherrill
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.