Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions Java String operations

Have Programming Question? Ask it here!
 
 
 


Neeraj
Java String operations
2 Answer(s)      2 years and 6 months ago
Posted in : Java Interview Questions


hi,

please suggest me how to write the java code for reading a file and ignore the commented lines in /......../ this dispaly the contents of the file without commented lines.


Advertisement
View Answers

October 4, 2011 at 3:31 PM


import java.io.*;
class ReadFileIgnoringSomeLines
{
    public static void main(String[] args) throws Exception
    {
        FileReader fr=new FileReader("data.txt");
        BufferedReader br=new BufferedReader(fr);
        StringBuffer buffer=new StringBuffer();
        String str;
        while((str=br.readLine())!=null){
            if(str.contains("//")||str.contains("/*")||str.contains("*/") ){
                continue;
            }
            else{
             buffer.append(str);
             buffer.append("\n");
            }

        }
        System.out.println(buffer.toString());
    }
}


October 4, 2011 at 5:10 PM


hi, Thanka a lot for help. Another help I need, please help me solve this problem.

please suggest me how to extract table name and find the no of select statement and insert statement from a file and dispaly the result of SELECT and INSERT tablewise i.e.

abc_table SELECT 4

pgm_table INSERT 5

Please tell me how to do the coding for this.



Related Tutorials/Questions & Answers:
Java String operations
Java String operations  hi, please suggest me how to write the java...*; class ReadFileIgnoringSomeLines { public static void main(String[] args... StringBuffer(); String str; while((str=br.readLine())!=null
java i/o operations
java i/o operations  how to write integer data to a file in java using random access file object or file writer or data outputstream i have already tried the write and writeInt methods....plz help
Advertisements
binary addition,subtraction and modulus operations - Java Beginners
passed as string without using java functions like parseInt,toString etc. i.e... passed as string into binary form, and then perform addition,subtraction and modulus operations on these two binary numbers and finally dipaly the result in decimal
Java JMenuItem to perform file operations
Java JMenuItem to perform file operations In this tutorial, you will learn how to use JMenuItem class to perform file operations. Java Swing introduced... example in java swing through which you can perform open and save operations
How to read the data in text file seperated by by ',' in java using IO Operations
How to read the data in text file seperated by by ',' in java using IO Operations  in Text file data like raju 45,56,67 ramu 46,65,78 raji 34,23,56 this is the student marks in text file.this data read and calculate
Operations with Calendar
Operations with Calendar  I have the following as my known parameter...*; import java.text.*; public class GetDateFromDay{ public String...()); } public static void main(String args[]){ GetDateFromDay dt
Java string
Java string  Strings are immutable.But String s="Hello"; String s1=s+"World"; S.O.P(s1); means printing "Hello World". How
Java String
Java String  You are given two strings S1 and S2,Delete from S2 all those characters which occur in s1 also and create a clean S2 with the relevant characters deleted..write a pgm for this..pls send as soon as possible Thank you
Java Swing Undo Redo Operations
Java Swing Undo Redo Operations Swing provides Undo and Redo functionality through javax.swing.undo package. The undo mechanisms allow users to unexecute...); setVisible(true); pack(); } public static void main(String[] args
Retrive data from database and perform binary tree operations on that data in jsp or java
Retrive data from database and perform binary tree operations on that data in jsp or java  To develop code for MLM project. I want to retrieve data from database dynamically and perform operations on that. Just like calculate
Retrive data from database and perform binary tree operations on that data in jsp or java
Retrive data from database and perform binary tree operations on that data in jsp or java  To develop code for MLM project. I want to retrieve data from database dynamically and perform operations on that. Just like calculate
String Number Operations in JavaScript
String Number Operations in JavaScript  ... of JavaScript and create your first JavaScript program.  What is String Number Operation? The JavaScript  String is a loosely type language. This is not mean
Reverse String using Stack
the string using these operations. Here is the code: import java.util....Reverse String using Stack You all are aware of Stack, a data structure, having two fundamental operations: push and pop. In stacks, items are removed
Java String - Java Beginners
Java String  How to seperate the string into characters.  there is a method called getChars() in String class,plz use that and separate into characters so plz verify the String api for related questions 
Java String
Java String       In this section, you will learn about the java string. Java String is a set... to a string literal in the object stream. The Java String object contains a sequence
string - Java Beginners
string in java interview questions  What is string in java? Interview questions
String in Java - Java Beginners
]); } } } ---------------------------------------------------- I am sending simple code of String array. If you are beginner in java...String in Java  hiiiii i initialise a String array,str[] with a size... in advance   Hello Antony Insted Using String Array Use StringBuffer
Java string buffer
Java string buffer  what is stringBuffer and StringBuilder
String immutable - Java Beginners
String immutable  Why is String immutable?  See here Why String is immutable in Java
How to convert into to String in Java?
How to convert into to String in Java?  Hi, How to convert into to String in Java? Thanks
capitalizing string in java
capitalizing string in java  How to capitalizing string in Java?   String s = "some string"; String capitol = Character.toString(s.charAt(0)).toUpperCase(); String newString = capitol + s.substring(1,x
How to Append String In Java?
How to Append String In Java?  How to write program in in Java for appending to a String? How to Append String In Java? What is the best way to do... the StringBuilder class. Check the example at Appending String in java. You can
converting string to double in java
converting string to double in java  Please post an example to converting string to double in java. Thanks!   Convert String to Double Tutorial
Java string buffer
Java string buffer  What is the basic difference between string and stringbuffer object
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
Java String Datatype
Java String Datatype  Weather String in java is class or Datatype,if it's clss then How can i assign String str="hello";   String is a class found in the package java.lang.*. When we represent string in double quotes
Core Java String
Core Java String  Hi , Here my code Class Test { String s1 = "null"; String s2 = "null"; String s3 = s1+s2; } what is the out put
On string - Java Beginners
On string -Display reverse String using string reverse method in Java  I wanted to display reverse String using string.reverse() method in Java  Display reverse String using string.reverse()String Reverse Using
java programmming: string manipulation
java programmming: string manipulation  WAP to accept a string from...' occurring in it   Here is a java example that reads a string from the command prompt and find the frequency of the character e in the input string
String - Java Interview Questions
Java String array declaration and initialization  I am looking for an example of java string array declaration and initialization  Hipublic class ImmutableCart { private final List items; public ImmutableCart(List
How To Append String In Java
How To Append String In Java In this section we will read about how to append String in Java. Here we will see the solution of this question through a simple example. There are various ways to append String in Java. Below, we
String Mirror in Java
String Mirror in Java  how to get a mirror image of(string) a given string in java   Hello Friend, Try this: import java.util.*; class StringMirror{ public static void main(String []args){ String str="hello
java string multiplication
java string multiplication  Is there any simple method of string multiplication in java ..?   public class StringMultiplication { public static void main(String[] args) { String number1 = "17"; String number2
Java String searching.
Java String searching.  How to search a string in given String array... static void main(String[] args) { String city[] = { "Delhi", "Lucknow", "Mumbai", "Kanpur" }; String userCity; Scanner scanner = new
Core Java -String
Core Java -String  Write a program to print "Ranjan pintu am i". the given string is i am pintu ranjan. here there is a condition, we can't use split() method, using loop only
java string comparison example
java string comparison example  how to use equals method in String... static void main(String [] args){ String str="Rose"; String str1... using equals() method. In the above example, we have declared two string
String and StringBuffer - Java Beginners
; Hi vijay Java provides the StringBuffer and String classes, and the String class is used to manipulate character strings that cannot be changed...String and StringBuffer  Dear Deepak Sir, What is String
Basic CRUD operations
=new ArrayList<Student>(); String client=request.getParameter...")) { System.out.println("I am in clent"); String id=request.getParameter("id"); String name=request.getParameter("name"); String college
Basic CRUD operations
=new ArrayList<Student>(); String client=request.getParameter...")) { System.out.println("I am in clent"); String id=request.getParameter("id"); String name=request.getParameter("name"); String college
Basic CRUD operations
=new ArrayList<Student>(); String client=request.getParameter...")) { System.out.println("I am in clent"); String id=request.getParameter("id"); String name=request.getParameter("name"); String college
Java: Example - String sort
Java: Example - String sort Sorting is a mechanism in which we sort the data... the string. The example given below is based on Selection Sort. The Selection sort...() // Sort a String array using selection sort. void sort(String
string - Java Beginners
string  hi, i need a source code for d following prgm; a java prgm which will read a string and rewrite it in the alphabetical order. for example... main(String [] args)throws IOException { String [] stringArray = new String[10
String Array - Java Beginners
String Array  Thanks for the help you had provided,,, Your solution did worked... I worked on the previous solution given by you and it worked.... I... again,,, and I'll come back to you , if I had other problem regarding JAVA
Java String manipulation
Java String manipulation  You are given two strings S1 and S2,Delete from S2 all those characters which occur in s1 also and create a clean S2 with the relevant characters deleted..write a pgm for this..pls send as soon
Java dom from string
Java dom from string  Hi, How to create dom tree from string data? I am trying to search the example for java dom from string. Thanks   ... UpdateData { public static void main(String[] args) { String url="http
string - Java Beginners
Converting into String in Java  Need an example of Converting into String in JavaThanks in Advance
String - Java Interview Questions
String  i have a String s1="abc"; String s2="123"; then how to get a String s3="a1b2c3
String program - Java Beginners
String program  write a program to accept a word. Pass it to the function magic(String x). The function checks the string for the presence... prints it is a magic string otherwise it prints not a magic string.  
string - Java Beginners
string  1. Write a program using string function to input any string... a string and display the string with the first character of every word in capital and the rest of the word in small letters. 3.A boy enters a string in which he
string - Java Beginners
string taken from the keyboard?  Hi Friend, Try the following code... main(String[] args) { System.out.println("Enter string"); Scanner input=new Scanner(System.in); String str=input.nextLine(); String newString=str.replace
 

 

 

DMCA.com