Results 21 to 29 of 29
- 04-10-2012, 02:13 PM #21
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 32
- Rep Power
- 0
Re: how to delete a line from a file in java
try
{
final StringBuilder stringBuilder = new StringBuilder();
InputStream inStream = new FileInputStream("D:\\Canvas\\dline.txt");
final InputStreamReader streamReader = new InputStreamReader(inStream, "UTF-8");
final BufferedReader bufferedReader = new BufferedReader(streamReader);
String line = "";
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
stringBuilder.append(line); }
}catch(Exception e){
System.out.println(e);
}
BUt still its displaying with junk characters
- 04-10-2012, 02:17 PM #22
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 32
- Rep Power
- 0
Re: how to delete a line from a file in java
if i use UTF-16 its working fine
- 04-10-2012, 02:20 PM #23
Re: how to delete a line from a file in java
I used "Unicode"
If you don't understand my response, don't ignore it, ask a question.
- 04-10-2012, 02:23 PM #24
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 32
- Rep Power
- 0
Re: how to delete a line from a file in java
Now from this unicode file i want to delete the second line and save the file with.xml extension. Should i use RandomAccessFile class for this?
- 04-10-2012, 02:31 PM #25
Re: how to delete a line from a file in java
You could. See post#2
If you don't understand my response, don't ignore it, ask a question.
- 04-10-2012, 02:32 PM #26
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 32
- Rep Power
- 0
Re: how to delete a line from a file in java
ok Thank u. I am able to do this...
- 04-11-2012, 09:34 AM #27
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 32
- Rep Power
- 0
Re: how to delete a line from a file in java
try
{
PrintWriter out = null ;
out = new PrintWriter (new FileWriter ("D:\\Canvas\\dline.xml"));
String line = null;
int lineNum = 0;
try {
FileInputStream in = new FileInputStream("D:\\Canvas\\dline.xcvs");
BufferedReader br1 = new BufferedReader(new InputStreamReader(in,"UTF-16"));
while( (line =br1.readLine()) != null) {
lineNum +=1;
if(lineNum == 2){
continue;
}
out.println(line);
}
System.out.println("Line deleted and converted to .xml file");
}
catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
out.flush();
out.close();
try {
FileInputStream in = new FileInputStream("D:\\Canvas\\dline.xcvs");
BufferedReader br1 = new BufferedReader(new InputStreamReader(in,"UTF-16"));
br1.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
catch(Exception e){
System.out.println(e);
}
This is the working code for the above problem..
- 04-18-2012, 03:19 AM #28
Member
- Join Date
- Apr 2012
- Location
- Spainish TOwn
- Posts
- 25
- Rep Power
- 0
- 04-18-2012, 03:21 AM #29
Similar Threads
-
[SOLVED] Delete Current line from file
By Azndaddy in forum New To JavaReplies: 2Last Post: 04-06-2012, 08:00 AM -
Java- Writing a file and reading a file line by line
By Nazneen Ali in forum New To JavaReplies: 7Last Post: 07-20-2011, 07:56 AM -
Trigger cmd to delete a file in java program
By hari.kr in forum Advanced JavaReplies: 4Last Post: 04-28-2010, 07:37 PM -
delete a line from a text file in Java
By ddatta8 in forum New To JavaReplies: 2Last Post: 01-24-2009, 05:08 AM -
How to edit/delete a line in *.dat file in java io and applets
By kalanidhi in forum New To JavaReplies: 1Last Post: 11-10-2008, 09:49 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks