[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

cannot get rid of the message Java Deprecated Class

Posted on 2007-03-23
9
Medium Priority
?
392 Views
Last Modified: 2010-03-31
I have simple class to read from text file.  the clas work ok, but the "deprecation" warrning is bugging me :(

C:\>javac FileInput.java -Xlint
FileInput.java:29: warning: [deprecation] readLine() in java.io.DataInputStream
has been deprecated
        System.out.println(dis.readLine());
                              ^
1 warning

C:\>javac FileInput.java
Note: FileInput.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

here is the class:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileInput {

  public static void main(String[] args) {
    File file = new File("C:\\que.sql");    
    try {
      fis = new File(file);
        
        BufferedReader in = new BufferedReader(new InputStreamReader(fis));
                
      while (in.available() != 0) {

     
        System.out.println(in.readLine());
      }

      fis.close();
     
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
0
Comment
Question by:salasadi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 18779580
that error looks like its coming from a different class that the one you posted.

To get rid of it use a BufferedReader instead of a DataInputStream (as you have done in the posted code)
0
 

Author Comment

by:salasadi
ID: 18780205
It was duplication .java file that confuse me.  I got it to work now, but some how the code loop after reach the null instead stopped:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
import java.io.*;
import java.text.*;

public class FileInput {
  public static void main(String[] args) {
    File file = new File("C:\\enabled.sql");    
    try {
        BufferedReader in = new BufferedReader(new FileReader(file));
         String line = in.readLine();
            while(line !=null) {      
                  System.out.println(in.readLine());
            }      
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
0
 
LVL 1

Expert Comment

by:alban4
ID: 18780476
Replace:
         String line = in.readLine();
            while(line !=null) {      
                  System.out.println(in.readLine());
            }      

With:
         String line;
            while((line = in.readLine()) !=null) {      
                  System.out.println(line);
            }      
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:salasadi
ID: 18780600
it works but the first line in the file is ignored!
0
 
LVL 1

Expert Comment

by:alban4
ID: 18780621
Make sure you're NOT declaring:
    String line = in.readLine();

It should be simply:
    String line;
0
 
LVL 20

Expert Comment

by:gatorvip
ID: 18781319
>>it works but the first line in the file is ignored!

Well, yes:

String line = in.readLine();   // read the first line
while(line !=null) {      
   System.out.println(in.readLine());  // read line, then print it
}

Nowhere do you actually print out the first line. You can either do what alban4 suggests, or make this modification :
String line = in.readLine();
System.out.println(line));  
while.....
0
 

Author Comment

by:salasadi
ID: 18781380
I modified the class as you suggested:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
import java.io.*;
import java.text.*;
public class FileInput {
  public static void main(String[] args) {
    File file = new File("C:\\test.txt");    
    try {
        BufferedReader in = new BufferedReader(new FileReader(file));
            while(in.readLine() !=null) {  
                  
                  System.out.println(in.readLine());
            }      
            in.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

here is my text file:

the is 1st test for read line
this is 2nd test
this is third test
this is 4th test

here is the java output:

C:\>java FileInput
this is 2nd test
this is 4th test

somehow I am skipping lines!

0
 
LVL 20

Assisted Solution

by:gatorvip
gatorvip earned 800 total points
ID: 18781454
You are skipping lines because you read twice, but only print once...


while(in.readLine() !=null) {       // you read once here, but you don't print
  System.out.println(in.readLine());  // you read again here, and you do print
}  
0
 
LVL 1

Accepted Solution

by:
alban4 earned 1200 total points
ID: 18781510
Modify the code as I suggested above:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
import java.io.*;
import java.text.*;
public class FileInput {
  public static void main(String[] args) {
    File file = new File("C:\\test.txt");    
    try {
        BufferedReader in = new BufferedReader(new FileReader(file));
        String line;
        while((line = in.readLine()) !=null) {      
            System.out.println(line);
         }    
          in.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question