473,404 Members | 2,179 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,404 software developers and data experts.

help in completing a method

Hey all, need help in a question

Complete the method below that is passed two strings, a name of a file and a target line. This method returns true if the file contains at least one line that matches the target line, and false otherwise. Note your method must include code to properly do the steps needed for file input.

public boolean containsLine (String filename, String target) {

any ideas?
May 10 '09 #1
3 1148
JosAH
11,448 Expert 8TB
@glitchy
Yes: read the very first article in this forum group; it contains a link that allows you to download the entire API documentation. Download it and start reading about BufferedReaders, FileInputStreams and the String class. They have all the methods you need.

kind regards,

Jos
May 10 '09 #2
something like this?

Expand|Select|Wrap|Line Numbers
  1. public boolean containsLine (String filename, String target) {
  2. try {
  3. BufferedReader in = new BufferedReader(new FileReader(filename));
  4. String line = null;
  5. while((line = in.readLine()) != null) {
  6. if(target.equals(line))return true;
  7. }
  8. }catch(IOException e){}
  9. return false;
  10. }
  11.  
May 10 '09 #3
JosAH
11,448 Expert 8TB
Yep, sort of; you only forgot to close your file when you're done with it; nothing a small finally { ... } block can't cure.

kind regards,

Jos
May 10 '09 #4

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

Similar topics

42
by: John | last post by:
Hello. I am a beginner to PHP and I am currently just going through a book, to create a simple form page. Unfortunately it doesn't work, and there is nothing listed on the books errata page on...
45
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
7
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong,...
2
by: JoshPeltier | last post by:
Hi, I am having problems installing vb.net on my laptop, running xp home. It will not install the frontpage client. I have updated windows and office(2000), yet still get the error. Here is the...
2
by: Vinny | last post by:
I'm writing a small ASP program which prompts the user for data. I would like to interactively validate the data as they are entering it, rather than waiting until they submit the form. So, I am...
2
by: Vinny | last post by:
A customer wants me to convert a VB app I wrote for them into a web app for remote users to do data entry. So, I'm writing a small ASP program which prompts the user for data, much like a VB...
1
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... There are a few questions wrapped up in this, but the main one is that the WebService.MyMethodAsync() methods that are automatically generated in the client code by VS 2005 don't seem to...
4
by: ShutterMan | last post by:
I have a JSON object as below (data is from SQL Server Northwind Database). But doing an eval on it returns an error "unterminated string constant" or such. Can someone help me pinpoint the...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.