How to read a text file using java code?
Here it is.
Full code available at -
https://github.com/namitsharma99/fileHandlingUsingJava
The class - com.java.code.ReadTextFile.java, reads a text file and displays its contents, making the best use of IO weapon - FileInputStream.
package
com.java.code;
import
java.io.FileInputStream;
public
class
ReadTextFile {
public
static
void
main(String[] args)
{
String
myExcelPath
= "sample";
textReader(myExcelPath);
}
private
static
void
textReader(String myTextPath)
{
FileInputStream
fileInputStream
= null;
try
{
fileInputStream
= new
FileInputStream(myTextPath);
int
c;
while
((c
= fileInputStream.read())
!= -1) {
System.out.print((char)
c);
}
if
(fileInputStream
!= null)
{
fileInputStream.close();
}
}
catch
(Exception e1)
{
System.out.println(e1);
}
}
}
Happy Coding!!
bhai awesome!!
ReplyDeleteThanks bro :)
DeleteIf you want to extend this program or others to other languages, platforms etc, let me know and I would definitely be interested in being a contributor.
Deletesounds great, the forum is open to every developer who is interested :)
Delete