473,396 Members | 1,914 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.

Help with removing only certain parts of text from a .txt document using java

Hi, i'm doing a project for my Java class and I know how to add text to a .txt document and remove the entire text but I do not know how to only remove certain parts of text. My code is supposed to allow users to add/remove text depending on the condition.

The code is



import java.io.*;
import java.util.*;

public class texteditor
{
public static void main(String args[])throws IOException
{

int maxIndx = 0;
String array[]= new String[10];
Scanner sc = new Scanner(new File("C:\\text\\text1.txt"));
while(sc.hasNext())
{//open while 3

maxIndx++;
array[maxIndx] = sc.nextLine();

}//close while 3

for(int j = 0; j<array.length; j++)
{
System.out.println(array[j]);
}
sc.close();

System.out.println("");

System.out.println("REMOVE:");

FileWriter fw = new FileWriter("C:\\text\\text1.txt");
PrintWriter nw = new PrintWriter(fw);

for(int k = 0; k<array.length; k++)
{

if(array[k] == "jacob")
{
break;
}
}
fw.close();
nw.close();
}
}

and it is supposed to interact with a folder int he C: drive called text with the text inside being (in this exact order)

text doc
_____________
Jacob is a bad
person and
he must
be punished.<<<<<<<<<<< part being removed with everything else remaining.

I know i'm supposed to use an array to make the program basically remove everythign and than re add it without putting the be punished part back in but i'm stuck as to how to set it up. If anyone can assist i would greatly appreciate it.
Mar 6 '08 #1
1 1627
sukatoa
539 512MB
Hi, i'm doing a project for my Java class and I know how to add text to a .txt document and remove the entire text but I do not know how to only remove certain parts of text. My code is supposed to allow users to add/remove text depending on the condition.

The code is



import java.io.*;
import java.util.*;

public class texteditor
{
public static void main(String args[])throws IOException
{

int maxIndx = 0;
String array[]= new String[10];
Scanner sc = new Scanner(new File("C:\\text\\text1.txt"));
while(sc.hasNext())
{//open while 3

maxIndx++;
array[maxIndx] = sc.nextLine();

}//close while 3

for(int j = 0; j<array.length; j++)
{
System.out.println(array[j]);
}
sc.close();

System.out.println("");

System.out.println("REMOVE:");

FileWriter fw = new FileWriter("C:\\text\\text1.txt");
PrintWriter nw = new PrintWriter(fw);

for(int k = 0; k<array.length; k++)
{

if(array[k] == "jacob")
{
break;
}
}
fw.close();
nw.close();
}
}

and it is supposed to interact with a folder int he C: drive called text with the text inside being (in this exact order)

text doc
_____________
Jacob is a bad
person and
he must
be punished.<<<<<<<<<<< part being removed with everything else remaining.

I know i'm supposed to use an array to make the program basically remove everythign and than re add it without putting the be punished part back in but i'm stuck as to how to set it up. If anyone can assist i would greatly appreciate it.
If i where to implement that, retrieve the text first from the .txt file to your storage...

You can now remove the text inside the storage, and write it again to a file...
Writing file with the same name overwrites the previous file...

I hope it helps,
Sukatoa
Mar 6 '08 #2

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

Similar topics

7
by: ???????J | last post by:
Javascript may inquire the push down menu value, can I inquire the description? The following example, the variable($answer) can be get the menu1's value. For example, if I select first data,...
8
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some...
2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
6
by: chris_fieldhouse | last post by:
Hi, I have a script for processing emails, The script finds email sent to a particular alias, grabs the body text of the email and stores it into a database. Problem is that certain character...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
3
by: Simon Brooke | last post by:
As various people will have noticed, I've been having a lot of trouble with XSL lately. Brief history: I wrote myself an XML toolkit back in 2000, and it worked well enough for me, so it's been...
4
by: civicjai | last post by:
Can anyone teach me how to An item code is to be entered by the user. If it is an existing item code that matches an item in the items array , a description of the item with its unit price is...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
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...
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.