Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hai again came with a another error in fileoutputstream  RSS feed

 
Matt Swaggi
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai friends when i compile this coding i cant find my input in the demo.txt
friends help me out in this and if you find any error please do alter the code
and show it to me !


CODE
import java.io.*;
public class MyInputeStream {

public static void main(String arg[])
{
try
{
int i ;
byte[] c = new byte[10];
String strFilePath = "f://File//demo.txt";
System.out.println("Enter the string value between 1 to 5 ");
for(i=0;i<5;i++)

c[i] = (byte)System.in.read();
FileOutputStream fos = new FileOutputStream(strFilePath);
byte strContent = ((byte) c[i]);

fos.write(strContent );

}
catch(IOException e)
{
e.printStackTrace();

}


}

}
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.

If you will use proper indentation you will see the problem (I changed the file path, and removed the unnecessary cast to byte):

What you want to do is write the contents in another loop.
 
Matt Swaggi
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir to be frank where the demo.txt will appear and how to trace the path coz
you haven't mentioned the full path as i have mentioned .
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the path is not specified, the file is created in the current working directory. See the Java Doc on java.io.File.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!