473,776 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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.prin tln("Enter file name:");
BufferedReader br0 = new BufferedReader( new InputStreamRead er(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.prin tln(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.prin tln(s1);
}
}
Jul 13 '07 #1
1 1590
r035198x
13,262 MVP
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.prin tln("Enter file name:");
BufferedReader br0 = new BufferedReader( new InputStreamRead er(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.prin tln(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.prin tln(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
5934
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 question that identifies the warning signs to look out for, the things that most easily and clearly identify the author of code as something less than a master of the art. I did not find an FAQ that answered it, but I think the FAQ
1
1278
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 that the IDE encounters an 'Error writing project file. Error loading type library/DLL.'... as i can remember, i created a C++ console application and a C# console application.... thats it...
7
1428
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 is sufficient. Can anyone confirm or deny? TIA...
1
1654
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
1502
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 several files that rarely change or are a list of the files in a directory that I rarely add or remove files from. Therefore, I want to be able to detect when a file is added to, removed from, or modified in one of these directories. Because I create...
5
3007
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
4124
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 on it.... I need to know the answer asap... please reply asap... thanks.
4
48776
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 type belpw Standard connection failed.
11
2134
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 file name corolla, file name Honda contain folder accord and BMW contain file name X5 Is there way to enter name of parent folder(cars) and search in all sub folder(Toyota,Honda and BMW) and files ? please help ASAP code is find most frequent...
0
9628
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10289
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5367
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.