473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Code is nt Detecting File...plz help asap....

here is a java code, wich is supposed to read a file name from user n read its contents and display it, bt its nt working..ne1 dere cud help me...jus copy n paste dis code in a notepad file wid name TsetofFile.java n save another input notepad file in bin to give it as input to code. Execute this code n give dat file name...bt its showng File nt found..watz rong in dis...plz help me asap...!!


import java.io.*;
import java.net.*;

class TestofFile
{
public static void main(String args[]) throws Exception
{
int i = 0;
String s2 = new String();
System.out.println("Enter file name:");
BufferedReader br0 = new BufferedReader(new InputStreamReader(System.in));
char c = 0;
do
{
c = (char) br0.read();
s2 = s2 + c;
i++;
} while (c != '\n' );
s2 = s2.substring(0,i-1);
System.out.println(s2);
FileInputStream file = new FileInputStream(s2);
String s1 = new String();
char f = 0;
do
{
f = (char) file.read();
s1 = s1 + f;
} while (f != '\n' );
System.out.println(s1);
}
}
Jul 13 '07 #1
1 1569
r035198x
13,262 8TB
here is a java code, wich is supposed to read a file name from user n read its contents and display it, bt its nt working..ne1 dere cud help me...jus copy n paste dis code in a notepad file wid name TsetofFile.java n save another input notepad file in bin to give it as input to code. Execute this code n give dat file name...bt its showng File nt found..watz rong in dis...plz help me asap...!!


import java.io.*;
import java.net.*;

class TestofFile
{
public static void main(String args[]) throws Exception
{
int i = 0;
String s2 = new String();
System.out.println("Enter file name:");
BufferedReader br0 = new BufferedReader(new InputStreamReader(System.in));
char c = 0;
do
{
c = (char) br0.read();
s2 = s2 + c;
i++;
} while (c != '\n' );
s2 = s2.substring(0,i-1);
System.out.println(s2);
FileInputStream file = new FileInputStream(s2);
String s1 = new String();
char f = 0;
do
{
f = (char) file.read();
s1 = s1 + f;
} while (f != '\n' );
System.out.println(s1);
}
}
1.) Please use code tags when posting code.
2.) This article explains how to read a file correctly.
Jul 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
1
by: tracernet_v2 | last post by:
help!!!! this is the first time i encountered this problem so please help, ASAP... when i try to create a new project, it creates the solution, but an error message box would appear telling me...
7
by: glen | last post by:
I'm looking for a way to detect if another process has a file open before a second process tries to open it. I've looked into the FileAttr function but I'm not sure if detecting a read-only state...
1
by: Massimo Bonanni | last post by:
Hi, I try to implement ASAP protocol in my web service, but I find a very hard problem. I define my SOAP Header: public class Request : SoapHeader {
3
by: Nathan Sokalski | last post by:
I have several pieces of data that I use the HttpApplicationState for, because they rarely change and are used by everyone. When these pieces of data are created, they are created either from...
5
by: Jens | last post by:
Posted to: comp.periphs.printers comp.lang.c comp.lang.postscript Hello, I am looking for some publically available methods/algorithms or C source code for detecting
24
jeffbroodwar
by: jeffbroodwar | last post by:
Hi everyone, Please help me accomplish the following : 1. how can i copy a file in java then paste it in a desired location 2. how can i run a .jar file run by just double clicking...
4
by: Pool | last post by:
I tried to connect DB2 (Sitting in Unix server at my client location) using Db2 connect V8. I am getting the following error message. I tried all the possible options BUt the error is same.. See each...
11
by: alivip | last post by:
how to ingrate my code to read text in in parent folder contain sub folders and files for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name Camry and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.