Results 1 to 4 of 4
Thread: File handling
- 03-23-2011, 07:41 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 61
- Rep Power
- 0
File handling
writer code:-
package reader_Writer;
import java.io.FileWriter;
import java.io.IOException;
public class My2
{
public static void main(String[] args) throws IOException}
{
FileWriter writer = null;}
try
{}
writer = new FileWriter("books.txt");
writer.write("java\n");
writer.write("hibernate\n");
writer.write("spring\n");
writer.write("android");
catch (IOException e)
{
e.printStackTrace();}
finally
{
if (writer != null)}
{
writer.flush();
writer.close();
writer=null;
}
is it necessary the below statement to be present in the above program.?
writer=null;
what is the use of writer=null;
ReaderCode:-
package reader_Writer;
import java.io.File;
import java.io.FileReader;
public class My2Extend
{
public static void main(String[] args)}
{
FileReader reader = null;}
try
{
reader = new FileReader("books.txt");}
int size = (int) new File("books.txt").length();
char all[] = new char[size];
reader.read(all);
String s1 = new String(all);
System.out.println(s1);
catch (Exception e)
{
e.printStackTrace();}
finally
{
try}
{
if (reader != null)}
{
reader.close();}
reader = null;
catch (Exception e2)
{
e2.printStackTrace();}
what is the use of reader = null; in the above reader code.?
- 03-23-2011, 08:27 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
No need of doing that. close() does all.
- 03-23-2011, 09:04 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 61
- Rep Power
- 0
- 03-23-2011, 09:28 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You mean that you want to read the file repeatedly ?
Similar Threads
-
File handling
By Dayanand in forum New To JavaReplies: 7Last Post: 03-23-2011, 07:31 AM -
File handling
By Dayanand in forum New To JavaReplies: 3Last Post: 03-22-2011, 04:20 PM -
File handling
By Claude2005 in forum New To JavaReplies: 17Last Post: 09-21-2010, 11:49 AM -
Regarding File Handling
By ravjot28 in forum New To JavaReplies: 1Last Post: 01-20-2010, 09:15 PM -
handling WAV file
By zellazode in forum New To JavaReplies: 1Last Post: 09-08-2009, 03:46 PM


LinkBack URL
About LinkBacks


Bookmarks