In this program I want to print the length of string in a external file but the problem is that it make the number of character in a string as a decimal value of character and prints the character which matches with the ascii value and print in a file.
import java.io.FileOutputStream;
class Fileoutputstream
{
public static void main(String args[])
{
try
{
FileOutputStream foul=new FileOutputStream("/root/Documents/YG2108/DemoFiles.txt");
String s="hello Sir ";
String s1;
byte by[]=s.getBytes();
foul.write(by);
s1="Good Afternoon have a nice day frghunv9uhbzsmk zvidzknmbnuf ofbdbmkxm;jccipx nc xdibnbnokcm knui9xkbmkl bv";
by=s.getBytes();
int yb=s.length();
int ascii = yb;
foul.write(ascii);
System.out.println("Sucess");
}catch(Exception e){System.out.println(e);}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…