Convert Short
to numeric primitive data types
public class
ShortToNumericPrimitiveTypesExample
{
public static void
main(String[] args)
{
Short sObj = new
Short("10");
byte b =
sObj.byteValue();
System.out.println(b);
short s =
sObj.shortValue();
System.out.println(s);
int i =
sObj.intValue();
System.out.println(i);
float f =
sObj.floatValue();
System.out.println(f);
double d =
sObj.doubleValue();
System.out.println(d);
long l =
sObj.longValue();
System.out.println(l);
}
}
Convert String
to short primitive
public class
StringToShortPrimitiveExample
{
public static void
main(String[] args)
{
String str = new
String("10");
short s =
Short.parseShort(str);
System.out.println(s);
}
}
Convert short
primitive to Short object
public class
shortToShortExample
{
public static void
main(String[] args)
{
short s = 10;
Short sObj = new
Short(s);
System.out.println(sObj);
}
}
Java Short
public class
ShortExample
{
public static void
main(String[] args)
{
short s = 10;
Short sObj1 = new
Short(s);
Short sObj2 = new
Short("10");
System.out.println(sObj1);
System.out.println(sObj2);
}
}
Read File Using
Java Buffered Input Stream
import java.io.*;
public class
ReadFileUsingBufferedInputStream
{
public static void
main(String[] args)
{
File file = new
File("C://FileIO//ReadFile.txt");
BufferedInputStream
bin = null;
try
{
FileInputStream fin =
new FileInputStream(file); bin = new BufferedInputStream(fin);
while( bin.available()
> 0 )
{
System.out.print((char)bin.read());
}
}
catch(FileNotFoundException
e)
{
System.out.println("File
not found" + e);
}
catch(IOException ioe)
{
System.out.println("Exception
while reading the file " + ioe);
}
finally
{
try
{
if(bin != null)
bin.close();
}
catch(IOException
ioe)
{
System.out.println("Error
while closing the stream : " + ioe);
}
}
}
}
No comments:
Post a Comment