String toFile

check my stupid problem
I have two progs AudioFrame1.java and ClipPlayer.java
My goal is to TextField(filename).getText()and run it as below
please help me.
ClipPlayer clipPlayer = new ClipPlayer(clipFile, nLoopCount);
AudioFrame1.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class AudioFrame extends JFrame implements ActionListener
{ JPanel p1=new JPanel();
JPanel p2=new JPanel();
JTextField filename=new JTextField(File);
JTextField loops=new JTextField(15);
JButton btnrun=new JButton("Run");
JButton btnclose=new JButton("Close");
JButton btnclear=new JButton("Clear");
AudioFrame()
setTitle("Play the Audio File");
initializeComponents();
this.setResizable(true);
this.setVisible(true);
this.setBounds(0,0,500,200);
void initializeComponents()
add(new Label(" "),BorderLayout.NORTH);
add(new Label(" "),BorderLayout.EAST);
add(p1,BorderLayout.EAST);
add(p2,BorderLayout.SOUTH);
p1.setLayout(new GridLayout(2,8));
p1.add(new JLabel("Audio File Name"));
p1.add(filename);
p1.add(new JLabel("Number of Loops"));
p1.add(loops);
p2.setLayout(new GridLayout(1,5));
p2.add(btnrun);
p2.add(btnclear);
p2.add(btnclose);
btnclear.addActionListener(this);
btnclose.addActionListener(this);
btnrun.addActionListener(this);
public void actionPerformed(ActionEvent e)
{ String fname;
int nLoopCount;
try{
if(btnrun==e.getSource())
{ fname=filename.getText();
nLoopCount = Integer.parseInt(loops.getText());
System.out.print("Running "+fname+" wave file ") ;
System.out.println(nLoopCount+" Times") ;
else if(btnclose==e.getSource()) {setVisible(false);System.exit(0);}
else if(btnclear==e.getSource()) clear(); }
catch(Exception ex){System.out.println(ex);}
void clear()
{   filename.setText("");
loops.setText("");
class AudioFrame1
public static void main(String args[])
AudioFrame f=new AudioFrame();
// ClipPlayer.java
// This file is part of jsresources.org
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
public class ClipPlayer implements LineListener
{ private Clip m_clip; /* * The clip will be played nLoopCount + 1 times.  */
public ClipPlayer(File clipFile, int nLoopCount)
{ AudioInputStream audioInputStream = null;
try
{ audioInputStream = AudioSystem.getAudioInputStream(clipFile);
catch (Exception e)
{ e.printStackTrace();
if (audioInputStream != null)
{ AudioFormat format = audioInputStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
try
{ m_clip = (Clip) AudioSystem.getLine(info);
m_clip.addLineListener(this);
m_clip.open(audioInputStream);
catch (LineUnavailableException e)
{ e.printStackTrace();
catch (IOException e)
{ e.printStackTrace();
m_clip.loop(nLoopCount);
else
{ out("ClipPlayer.<init>(): can't get data from file " + clipFile.getName());
public void update(LineEvent event)
{ if (event.getType().equals(LineEvent.Type.STOP))
{ System.out.print("    stop");m_clip.close();
if (event.getType().equals(LineEvent.Type.OPEN))
{ System.out.print("open");
else if (event.getType().equals(LineEvent.Type.CLOSE))
{ System.out.println("     close");
System.exit(0);
public static void main(String[] args)
{ AudioFrame f=new AudioFrame();
public toFile(String good)
{ File fil=f.filename.getString();
if (args.length != 2)
{ out("ClipPlayer: usage:   java ClipPlayer <ringout.wav> <0+1 times>\n");
else
File clipFile = new File(args[0]);
int nLoopCount =Integer.parseInt( args[1]);
ClipPlayer clipPlayer = new ClipPlayer(clipFile, nLoopCount);
while (true)
{ try
{ Thread.sleep(0);/* sleep for 1 second. */
catch (InterruptedException e)
{ // Ignore the exception.
private static void out(String strMessage)
{ System.out.println(strMessage +"It will not run if you don't give parameters");
System.out.println(strMessage +"type as ClipPlayer chord.wav 0");
} /*** ClipPlayer.java ***/

Stupid is right.
Do you have a question about that code? And why did you post it in this forum?

Similar Messages

  • Accessing string from other classes

    Sorry if this seems simple to you, but i'm having problems accessing four string that are declared and used in my public class from another class.
    I've tried declaring the strings public but it still says 'cannot resolve symbol' when i try to compile.
    Help much appreciated.
    fightspam

    Yep, heres my code(sorry if it's a bit untidy):
    //Zimmerman M3 email client.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    class where extends JFrame implements ActionListener
         private JLabel path;
         private JTextField pathText;
         private String pathFile;
         private JButton save;
         File outputFile = new File(pathFile);
         public where()
              super("Save Email");     
              Container f=getContentPane();
                   f.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
              f.setBackground(Color.lightGray);
              path = new JLabel("Path: ");
              f.add(path);
              pathText = new JTextField(20);
              f.add(pathText);
              save = new JButton("Save");
              f.add(save);
              this.setSize(300, 100);
         public void actionPerformed(ActionEvent q)
              pathFile = pathText.getText();
              try
                   FileWriter out = new FileWriter(outputFile);
                   out.write(zimmernorm.toFile);
                   out.write(zimmernorm.fromFile);
                   out.write(zimmernorm.subjectFile);
                   out.write(zimmernorm.bodyFile);
                   out.close();
              catch(IOException err)
                   System.exit(0);
    class about extends JFrame
         private JLabel title;
         public about()
              super("About Zimmerman M3");
              Container d=getContentPane();
                   d.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
              d.setBackground(Color.lightGray);
              title = new JLabel("Zimmerman M3 by Louis Goddard, 2003");
              d.add(title);
              this.setSize(246, 62);
    class newmail extends JFrame implements ActionListener
         public static String toFile, fromFile, subjectFile, bodyFile;
         public JTextField To, From, Subject;
         private String toBuffer, fromBuffer, subjectBuffer, bodyBuffer;
         private JButton send, clear;
         private JTextArea Body;
         private JLabel toLabel, fromLabel, subjectLabel;
         private JMenuBar mb;
         private JMenu File, Edit;
         private JMenuItem New, Sender, Copy, Paste, About;
         public newmail()
                    super("New Email");
              Container c=getContentPane();
                   c.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
              c.setBackground(Color.lightGray);
              //<MENU STUFF!!!>     
                   mb = new JMenuBar();
                   File = new JMenu("File");
                   Edit = new JMenu("Edit");
                   New = new JMenuItem("New");
                   Sender = new JMenuItem("Save");
                   Copy = new JMenuItem("Copy");
                   Paste = new JMenuItem("Paste");
                   File.add(New);
                   New.addActionListener(this);
                   New.setActionCommand("1");
                   File.add(Sender);
                   Sender.addActionListener(this);
                   Sender.setActionCommand("2");
                   Edit.add(Copy);
                   Copy.addActionListener(this);
                   Copy.setActionCommand("3");
                   Edit.add(Paste);
                   Paste.addActionListener(this);
                   Paste.setActionCommand("4");
                   mb.add(File);
                   mb.add(Edit);
                   setJMenuBar(mb);
              //</MENU STUFF!!!>     
              toLabel = new JLabel("To:          ");
              c.add(toLabel);
              To = new JTextField(35);
              c.add(To);
              fromLabel = new JLabel("From:     ");
              c.add(fromLabel);
              From = new JTextField(35);
              c.add(From);
              subjectLabel = new JLabel("Subject:");
              c.add(subjectLabel);
              Subject = new JTextField(35);
              c.add(Subject);
              Body = new JTextArea(12,40);
              c.add(Body);
              send = new JButton("Send");
                    c.add(send);
              clear = new JButton("Clear");
                    c.add(clear);
              clear.addActionListener(this);
              clear.setActionCommand("6");
              this.setSize(459, 364);
              public static void main(String []args)
                   JFrame.setDefaultLookAndFeelDecorated(true);
                   new newmail().show();
              public void actionPerformed(ActionEvent e)
                   String s = e.getActionCommand();
                   if (s == ("1"))
                   new newmail().show();
                   else if (s == ("2"))
                   new where().show();
                   toFile = To.getText();
                   fromFile = From.getText();
                   subjectFile = Subject.getText();
                   bodyFile = Body.getText();
                   else if (s == ("3"))
                   bodyBuffer = Body.getSelectedText();
                   toBuffer = To.getSelectedText();
                   fromBuffer = From.getSelectedText();
                   subjectBuffer = Subject.getSelectedText();
                   else if (s == ("4"))
                   Body.setText(bodyBuffer);
                   To.setText(toBuffer);
                   From.setText(fromBuffer);
                   Subject.setText(subjectBuffer);
                   else if (s == ("5"))
                   new about().show();
                   else if (s == ("6"))
                   To.setText("");
                   From.setText("");
                   Subject.setText("");
                   Body.setText("");
    public class zimmernorm extends JFrame implements ActionListener
         public String toFile, fromFile, subjectFile, bodyFile;
         private String toBuffer, fromBuffer, subjectBuffer, bodyBuffer;
         private JMenuBar mb;
         private JMenu File, Help, View;
         private JMenuItem New, About, Inboxmenu, Outboxmenu, Savedmenu;
         public zimmernorm()
                    super("Zimmerman M3");
              Container c=getContentPane();
                   c.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
              c.setBackground(Color.lightGray);
              //<MENU STUFF!!!>     
                   mb = new JMenuBar();
                   File = new JMenu("File");
                   View = new JMenu("View");
                   Help = new JMenu("Help");
                   New = new JMenuItem("New");
                   About = new JMenuItem("About");
                   Inboxmenu = new JMenuItem("Inbox");
                   Outboxmenu = new JMenuItem("Outbox");
                   Savedmenu = new JMenuItem("Saved");
                   File.add(New);
                   New.addActionListener(this);
                   New.setActionCommand("1");
                   Help.add(About);
                   About.addActionListener(this);
                   About.setActionCommand("5");
                   View.add(Inboxmenu);
                   Inboxmenu.addActionListener(this);
                   Inboxmenu.setActionCommand("7");
                   View.add(Outboxmenu);
                   Outboxmenu.addActionListener(this);
                   Outboxmenu.setActionCommand("8");
                   View.add(Savedmenu);
                   Savedmenu.addActionListener(this);
                   Savedmenu.setActionCommand("9");
                   mb.add(File);
                   mb.add(Help);
                   mb.add(View);
                   setJMenuBar(mb);
              //</MENU STUFF!!!>     
              this.setSize(1024, 768);
                    this.setDefaultCloseOperation( EXIT_ON_CLOSE );
              public static void main(String []args)
                   JFrame.setDefaultLookAndFeelDecorated(true);
                   new zimmernorm().show();
              public void actionPerformed(ActionEvent e)
                   String s = e.getActionCommand();
                   if (s == ("1"))
                   new newmail().show();
                   else if (s == ("5"))
                   new about().show();

  • Copy file from directory to another directory

    I need to copy a file from a directory to another directory, but that file is longer than 2M.
    I put the data into a array of bytes and then i passed to a destination directory.
    Now i'm using a BufferedOutputStream but, as i have a file whith 2M, and this dont work.
    How can i resolve this problem.
    Thanks, Luis

    I use This, and it works with all kinds of files. I use it for backups with thousands of files and subdirectories.
    you can use this like "copyFiles("D:\\Source", "D:\\Destination")
    The two directories in the parameter list must exist. Subdirectories will be generated from the method.
    I hope this will help you.
    private void copyFiles(String fromPath, String toPath)
         // copies all files and it�s subdirectories from fromPath to toPath
         // fromPath and toPath must exist
              if (fromPath != null)
                   File dir = new File(fromPath);
                   if (dir.exists() && dir.isDirectory())
                        File [] fileList = dir.listFiles();
                        int count = fileList.length;
                        int i = 0;
                        while (i < count)
                             File f = fileList;
                             i++;
                             if (f.isFile())
                                  String toFile = toPath + File.separator + f.getName();
                                  copyFile(f.getPath(), toFile);
                             else
                                  if (f.isDirectory())
                                       File newPath = new File(toPath + File.separator + f.getName());
                                       newPath.mkdirs();
                                       copyFiles(f.getPath(), newPath.getPath());
                        }// while (i < count
                   }// if (dir.exists() && dir.isDirectory())
              }// if (fromPath != null)
         }// copyFiles(String fromPath, String toPath)
    private void copyFile(String src, String dest)
    // Copies a single File with date and time attributes
              long fileTime;
              try
                   FileChannel in = new FileInputStream(src).getChannel();
                   FileChannel out = new FileOutputStream(dest).getChannel();
                   File inInfo = new File(src);
                   fileTime = inInfo.lastModified();
                   in.transferTo(0, in.size(), out);
                   in.close();
                   out.close();
                   File outInfo = new File(dest);
                   outInfo.setLastModified(fileTime);
              } catch (IOException ioe)
                   System.out.println("An error occured: " + ioe.getMessage());

  • How to call a java method in a Stored procedure

    Hi.,
    I was trying to call a method in a stored procedure
    This was my procedure
    CREATE OR REPLACE PROCEDURE proc_copy_file(sr_file VARCHAR2,dt_file VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'FileCopy.copyfile(String,String)'; // calling a java method
    /   this was my java method
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "FileCopy" as
    import java.io.File;
      import java.io.IOException;
      import java.io.FileReader;
      import java.io.FileWriter;
      import javax.imageio.stream.FileImageInputStream;
      import javax.imageio.stream.FileImageOutputStream;
      import java.security.AccessControlException;
      public class FileCopy {
          // Define variable(s).
              private static int c;
              private static File file1,file2;
              private static FileReader inTextFile;
              private static FileWriter outTextFile;
              private static FileImageInputStream inImageFile;
              private static FileImageOutputStream outImageFile;
              // Define copyText() method.
              public static void copyfile(String fromFile,String toFile) throws AccessControlException
                // Create files from canonical file names.
                file1 = new File(fromFile);
                file2 = new File(toFile);
                // Copy file(s).
                try
                  // Define and initialize FileReader(s).
                  inTextFile  = new FileReader(file1);
                  outTextFile = new FileWriter(file2);
                  // Read character-by-character.
                  while ((c = inTextFile.read()) != -1) {
                    outTextFile.write(c); }
                  // Close Stream(s).
                  inTextFile.close();
                  outTextFile.close(); }
                catch (IOException e) {
                  System.out.println ("-------"); }
             // return 1;
          public static void main(String[] args){
                          switch(args.length){
                                  case 0: System.out.println("File has not mentioned.");
                                                  System.exit(0);
                                  case 1: System.out.println("Destination file has not mentioned.");
                                                  System.exit(0);
                                  case 2: copyfile(args[0],args[1]);
                                                  System.exit(0);
                                  default : System.out.println("Multiple files are not allow.");
                                                    System.exit(0);
    };while i am executing this method i m getting error as
    ORA-29531: NO METHOD COPYFILE IN CLASS FILECOPY
    ORA-06512: AT "RMVER721.PROC_COPY_FILE", LINE 1could anyone help me

    Looks like it is a matter of not quite the same namespace for String object.
    I can get it to work by the java source containing:
              public static void copyfile(java.lang.String fromFile,java.lang.String toFile) throws AccessControlExceptionAnd the PL/SQL source:
    NAME 'FileCopy.copyfile(java.lang.String,java.lang.String)'; // calling a java methodSeems like when you just use "String", then the namespace resolving in the java source is not the same as the namespace resolving in the PL/SQL?
    Addendum:
    You do not need to put java.lang.String in the java source, String will do (java.lang is by default "imported"?)
    But in the PL/SQL source java.lang namespace prefix is needed - java.lang is not "imported" here.
    Edited by: Kim Berg Hansen on Nov 23, 2011 1:07 PM

  • I am in horry please if some one can help me with my FTP code, thanks

    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Ass_2 {
         public static void main(String[] args){
              String currentPath = new String(); currentPath = "ftp://ftp.scit.wlv.ac.uk/pub";
              try {
                   BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                   String str,user,pass ;
                   System.out.println("\n\nTYPE HELP for view the list of commands and there Formats!!");
                   System.out.println("enter command 'bye' to exit the application");
                        System.out.print("Enter Username: ");
                        user = in.readLine();     
                        System.out.print("Enter Password: ");
                        pass = in.readLine();
                        String tempPath = new String();
                        String toFile = new String();
                        tempPath = currentPath ;
                        readPage(currentPath);
                   while (!(str = in.readLine()).equals("bye")){     
                        int     tokencount;
                        StringTokenizer     token = new StringTokenizer(str);
                        tokencount = token.countTokens();
                        String block[] = new String[tokencount];
                        for (int i = 0; i < tokencount; i++)
                             block[i] = token.nextToken();
                             System.out.println(block);
                        if (block[0].equalsIgnoreCase("dir")){
                             System.out.println("DIR");
                             System.out.println(currentPath);
                             readPage(currentPath);
                             System.out.println("\n");
                        }else if(block[0].equalsIgnoreCase("cwd")){
                             System.out.println("Change Directory");
                             currentPath = changeDirectory(currentPath, block[1]);
                             System.out.println("\n");
                        }else if(block[0].equalsIgnoreCase("get")){
                             System.out.println("Wait Copying File : "+block[1]);
                             copyFile(currentPath,block[1]);
                        }else if(block[0].equalsIgnoreCase("cd..")){
                             currentPath = goBack(currentPath);               
                        }else if(block[0].equalsIgnoreCase("help")){
                             System.out.println("\nYour in the Help Section \n");
                        }else {
                             System.out.println("Wrong Command or Format, Type Help!!!");
                             System.out.println("\n");
              catch(Exception e){
                   System.out.println(e);
         // Function to read content form the specfied path
         static void readPage(String path){
              String tempPath = new String();
              try {     
                   URL     pageref = new URL(path);
                   InputStream in = pageref.openStream();
                   BufferedReader inline = new BufferedReader(new InputStreamReader(in));//(instr);
                   String     line;
                   int     linect = 0;
                   while((line = inline.readLine())!=null){
                        linect++;
                        System.out.println(line);
                   System.out.println("lines read = "+linect);
              catch(Exception e){
                   System.out.println(e);
         static String changeDirectory(String path,String dir){
              path = path+"/"+dir;//System.out.println(">>>>>>>>>>> " path" >>> \n");
              readPage(path);     
              return path;
         // Function to go one setp back from the current directory
         static String goBack(String currentPath){
              return currentPath;
         /// Function for basic copy TXT file
         static void copyFile(String path,String file){
              try {
                   path = path +"/"+ file;     //System.out.println("Copy Path : " + path);
                   String fileName = new String();
                        fileName = file+".txt";
                        System.out.println("Out put file name : " + fileName);
                   OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(fileName));
                   URL     pageref = new URL(path);
                   InputStream in = pageref.openStream();
                   BufferedReader inline = new BufferedReader(new InputStreamReader(in));//(instr);
                   String     line;
                   int     linect = 0;
                   while((line = inline.readLine())!=null){
                        System.out.println(line);
                        linect++; //System.out.println(line);
                        out.write(line+"\r\n");
                   out.close();               
                   System.out.println("File - " file " - copyed Successfully !!");
              catch(Exception e){
                   System.out.println(e);

    h2. {color:#ff0000}Double post{color}
    Replies here:
    http://forum.java.sun.com/thread.jspa?threadID=5253627
    It's rude to double post.
    It's futile (at best) to advertise your time pressure.
    It's pointless to use a forum like this but not actually ask a question.

  • My JList does not scroll

    hello forum,
    my JList (indentifier=PKGList) does not scroll. Can any look at code and tell me what's the problem. Following is the code. To test this code create two files in same directory. No package statement is there in code.
    1. javaEditor.java
    2. key_words.java
    copy the respective codes. compile these files.
    run command >> java javaEditor .
    Then my GUI will appear. click "new file" from file menu.
    then type "import". press SPACE BAR. a list box will appear conatining list of some packages.
    This is where the problem is [b]. this list box does not sroll.
    at some places,for the ease of identification, i have put the comments..
    ///PAY ATTENTION HERE BEGINS
    and
    ///PAY ATTENTION HERE ENDS .
    I will be thankfull whoever helps me.
    /* javaEditor.java  */
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.lang.reflect.*;
    public class javaEditor extends JFrame
         JMenuBar menubar;
         JMenu menu;
         JMenuItem menuitem;
         Container pane;
         Package PKGname;     
         JList PKGlist;
         Vector files;
         Vector PACKAGE;
         static Vector ClassList;
         JTextArea JTA;
         char flag;
         javaEditor()
              super("JavaEditor");
              PACKAGE=new Vector();
              files= new Vector();          
              ClassList=new Vector();
              flag='0';
              pane=getContentPane();          
              pane.setLayout(null);
              window_listener WL=new window_listener(this);
              addWindowListener(WL);
              action_listener AL=new action_listener(this);
              PKGlist=new JList();
              Package pkg[]=Package.getPackages();
              for (int i=0;i<pkg.length;i++)
                   PACKAGE.add(i,pkg.getName());               
              }//for
    [I]
    ///PAY ATTENTION HERE BEGINS
              PKGlist.setListData(PACKAGE);          
              JScrollPane scrollPane = new JScrollPane(PKGlist);
              PKGlist.setAutoscrolls(true);
              pane.add(PKGlist);
    ///PAY ATTENTION HERE ENDS
              ////////////File menu//
              menubar=new JMenuBar();          
              setJMenuBar(menubar);
              menu=new JMenu("File");     
                   menuitem=new JMenuItem("New File");
                   menuitem.addActionListener(AL);
                   menu.add(menuitem);
                   menuitem=new JMenuItem("Open");
                   menuitem.addActionListener(AL);
                   menu.add(menuitem);
                   menuitem=new JMenuItem("Save As...");
                   menuitem.addActionListener(AL);
                   menu.add(menuitem);
              menubar.add(menu);
              menu=new JMenu("Edit");
                   menuitem=new JMenuItem("Cut");
                   menuitem.addActionListener(AL);
                   menu.add(menuitem);
                   menuitem=new JMenuItem("Copy");
                   menuitem.addActionListener(AL);
                   menu.add(menuitem);
                   menuitem=new JMenuItem("Paste");
                   menuitem.addActionListener(AL);
                   menu.add(menuitem);
              menubar.add(menu);          
              setJMenuBar(menubar);          
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         }//javaEditor()
         public static void main(String s[])
              javaEditor JE =new javaEditor();
              JE.setSize(500,500);
              JE.setVisible(true);
         }//public static void main(String s[])
         public boolean isClass(String str)
              int i=0;
              System.out.println("searching"+str+" ................");
              while(i<javaEditor.ClassList.size())
                   Class c=(Class)javaEditor.ClassList.elementAt(i);
                   String str1=c.getName();
                   str1=str1.substring(str1.lastIndexOf('.')+1);
                   System.out.println("\t\tMaching with "+str1);
                   if(str1.equals(str))
                        System.out.println("....mached");
                        return true;                    
                   i++;
              return false;
         public Class  findClass(String str)
              int i=0;
              while(i<javaEditor.ClassList.size())
                   Class c=(Class)javaEditor.ClassList.elementAt(i);
                   String str1=c.getName();
                   str1=str1.substring(str1.lastIndexOf('.')+1);
                   if(str1.equals(str))
                        return c;
                   i++;
              return null;
    }//javaEditor extends JFrame
    class action_listener implements ActionListener
         javaEditor JE;
         action_listener (javaEditor JE1)
              JE=JE1;
         public void actionPerformed(ActionEvent e)
              if (e.getActionCommand()=="New File")//adds JTEXT AREA
                   FileOpener file_opener=new FileOpener(JE);
                   file_opener.openNewFile();
                   JE.files.add(FileOpener.counter,file_opener);
              if (e.getActionCommand()=="Open")
                   try
                        JFileChooser chooser = new JFileChooser();               
                        int returnVal = chooser.showOpenDialog(JE);
                        if(returnVal == JFileChooser.APPROVE_OPTION)
                            System.out.println("You chosed to open this file: "+
                             chooser.getSelectedFile().getName());                    
                             FileOpener file_opener=new FileOpener(JE);
                             file_opener.openFile(chooser.getSelectedFile());
                             JE.files.add(FileOpener.counter,file_opener);
                        }//if(returnVal == JFileChooser.APPROVE_OPTION)
                   }//try
                   catch(Exception excptn)
                        System.out.println(excptn);
                   }//catch(Exception excptn)
              if (e.getActionCommand()=="Save As...")
                   try
                        JFileChooser chooser = new JFileChooser();               
                        int returnVal = chooser.showSaveDialog(JE);
                        if(returnVal == JFileChooser.APPROVE_OPTION)
                           System.out.println("You chose to save this file: " +
                                  chooser.getSelectedFile().getName());
                           FileOutputStream fileOS=new FileOutputStream(chooser.getSelectedFile());
                          //String tofile=JTA.getText();
                          //fileOS
                        }//if(returnVal == JFileChooser.APPROVE_OPTION)
                   catch(Exception ex)
              }//if (e.getActionCommand()=="Save As...")          
         }//actionPerformed(ActionEvent e)
    }//action_listener implements ActionListener
    class window_listener extends WindowAdapter
         javaEditor JE;
         window_listener(javaEditor JE1)
              JE=JE1;
    }//window_listener extends WindowAdapter
    class key_listener implements KeyListener
              JTextArea JTA;
              javaEditor JE;
              StringTokenizer str_tok;
              key_listener (JTextArea JTA1,javaEditor JE1)
                   JTA=JTA1;
                   JE=JE1;
          public void keyPressed(KeyEvent e)
               if (e.getSource()==JTA)
                        Character c = new Character(e.getKeyChar());
                        String str= JTA.getText()+c.toString();
                        String str1="hsdk";
                        if(JTA.getCaretPosition()!=0)
                        str=str.substring(0,JTA.getCaretPosition()+1);
                        str_tok=new StringTokenizer(str," \n\r\t;:{}%\\+-*&!.");
                        while(str_tok.hasMoreTokens())
                             str1=str_tok.nextToken();
                        //while(str_tok.hasMoreTokens())
                        if(key_words.isKeyWord(str1))
                             System.out.println("key word "+str1);
                             if(str1.equals("import"))
                                  JE.flag='p';                                             
                             else
                                  JE.flag='k';                                             
                        }//if(key_words.isKeyWord(str1))
                        else if(JE.isClass(str1))
                             System.out.println("class is in list");
                        else if(c.equals(new Character(' '))||c.equals(new Character('.')))
                             Class CLASS;
                             ClassSearch.ifClassAddToList(str1);                                
                             if(JE.isClass(str1))
                                  Method methods[];
                                  System.out.println("searching "+str1+" class into list");
                                  CLASS=JE.findClass(str1);
                                  System.out.println("after finding "+CLASS.getName());
                                  methods=CLASS.getDeclaredMethods();
                                  for(int i=0;i<methods.length;i++)
                                       System.out.println(methods.toString());
                             System.out.println("proceeding............");
                             //CS.start();                    
                        if(JE.flag=='p' && c.equals(new Character(' ')))
                             Caret crt=JTA.getCaret();
                             Point p=crt.getMagicCaretPosition();
    [I]
    ///PAY ATTENTION HERE BEGINS
                             JE.PKGlist.setVisible(true);
                             JE.PKGlist.grabFocus();
                             JE.PKGlist.setOpaque(true);
                             JE.PKGlist.setBackground(new Color(150,150,150));                         
                             JE.PKGlist.setBounds(p.x+JTA.getX()+10,p.y+JTA.getY()+60,50,100);
    ///PAY ATTENTION HERE ENDS
                        }//if(JE.flag=='p' && c.equals(new Character(' ')))
                        if(JE.flag=='C' && c.equals(new Character(' ')))
                        JTA.repaint();
                        JE.pane.repaint();
               }///if e.getSource()
               if (e.getSource()==JE.PKGlist)
                    if(e.getKeyCode()==e.VK_ENTER||e.getKeyCode()==e.VK_SPACE||e.getKeyCode()==e.VK_TAB)
                              JE.PKGlist.setVisible(false);
                              String selectedstr=(String)JE.PKGlist.getSelectedValue();
                              System.out.println(selectedstr);
                              String toAdd=" "+selectedstr+".*;";
                              JTA.insert(toAdd,JTA.getCaretPosition());
                              JTA.grabFocus();
                              JE.flag='0';
                    }//if(e.getKeyCode()==e.VK_ENTER.....
               }//if (e.getSource()==JE.PKGlist)
          public void keyReleased(KeyEvent e){}//keyReleased ends
          public void keyTyped(KeyEvent e){}//keyTyped ends
    class FileOpener
         javaEditor JE;
         static int counter=-1;
         String name;
         JTextArea JTA;
         JInternalFrame  JIF;
         boolean isSaved;
         FileOpener(javaEditor JE1)
              JE=JE1;
              counter++;
              name=new String("NoName-"+Integer.toString(counter)+".java");
              JTA=new JTextArea();          
              isSaved=false;
         }//FileOpener(javaEditor JE1)
         public void openNewFile()
                   JIF=new JInternalFrame(name,true, true, true, true) ;
                   JIF.setBounds(0,10,JE.getWidth(),JE.getHeight()-50);               
                   JTA.setBounds(0,20,JE.getWidth(),JE.getHeight()-50);               
                   key_listener KL=new key_listener(JTA,JE);
                   JTA.addKeyListener(KL);
                   JE.PKGlist.addKeyListener(KL);
                   JIF.getContentPane().add(JTA);               
                   JIF.setVisible(true);
                   JE.pane.add(JIF);
                   JE.repaint();
                   JIF.grabFocus();     
                   JIF.moveToFront();
                   JTA.grabFocus();
         }//openNewFile()
         public void openFile(File file) throws FileNotFoundException,IOException
                   JIF=new JInternalFrame(file.getName(),true, true, true, true) ;
                   JIF.setBounds(0,10,JE.getWidth(),JE.getHeight()-50);               
                   JTA.setBounds(0,20,JE.getWidth(),JE.getHeight()-50);               
                   FileInputStream fileInputStream=new FileInputStream(file);
                   byte buf[]=new byte[fileInputStream.available()];
                   fileInputStream.read(buf);
                   JTA.setText(new String(buf));
                   key_listener KL=new key_listener(JTA,JE);
                   JTA.addKeyListener(KL);
                   JE.PKGlist.addKeyListener(KL);
                   /************************************************************/          JIF.getContentPane().add(JTA);
                   JIF.setVisible(true);
                   JE.pane.add(JIF);
                   JE.repaint();
                   JIF.grabFocus();     
                   JIF.moveToFront();
                   JTA.grabFocus();
         }//openFile(File file)
    }//class FileOpener
    class ClassSearch //extends Thread
         public static  void ifClassAddToList(String str)
              String pkg[]=  new String[77];
              pkg[0]=new String("java.applet.");
              pkg[1]=new String("java.awt.");
              pkg[2]=new String("java.awt.color.");
              pkg[3]=new String("java.awt.datatransfer.");
              pkg[4]=new String("java.awt.dnd.");
              pkg[5]=new String("java.awt.event.");
              pkg[6]=new String("java.awt.font.");
              pkg[7]=new String("java.awt.geom.");
              pkg[8]=new String("java.awt.im.");
              pkg[9]=new String("java.awt.im.spi");
              pkg[10]=new String("java.awt.image.");
              pkg[11]=new String("java.awt.image.renderable");
              pkg[12]=new String("java.awt.print.");
              pkg[13]=new String("java.beans.");
              pkg[14]=new String("java.beans.beancontext.");
              pkg[15]=new String("java.io.");
              pkg[16]=new String("java.lang.");
              pkg[17]=new String("java.lang.ref.");
              pkg[18]=new String("java.lang.reflect.");
              pkg[19]=new String("java.math.");
              pkg[20]=new String("java.net.");
              pkg[21]=new String("java.rmi.");
              pkg[22]=new String("java.rmi.activation.");
              pkg[23]=new String("java.rmi.dgc.");
              pkg[24]=new String("java.rmi.registry.");
              pkg[25]=new String("java.rmi.server.");
              pkg[26]=new String("java.security.");
              pkg[27]=new String("java.security.acl.");
              pkg[28]=new String("java.security.cert.");
              pkg[29]=new String("java.security.interfaces.");
              pkg[30]=new String("java.security.spec.");
              pkg[31]=new String("java.sql.");
              pkg[32]=new String("java.text.");
              pkg[33]=new String("java.util.");
              pkg[34]=new String("java.util.jar.");
              pkg[35]=new String("java.util.zip.");
              pkg[36]=new String("javax.accessibility.");
              pkg[37]=new String("javax.media.sound.midi.");
              pkg[38]=new String("javax.media.sound.midi.spi.");
              pkg[39]=new String("javax.media.sound.sampled.");
              pkg[40]=new String("javax.media.sound.sampled.spi.");
              pkg[41]=new String("javax.naming.");
              pkg[42]=new String("javax.naming.directory.");
              pkg[43]=new String("javax.naming.event.");
              pkg[44]=new String("javax.naming.ldap.");
              pkg[45]=new String("javax.naming.spi.");
              pkg[46]=new String("javax.rmi.");
              pkg[47]=new String("javax.rmi.CORBA.");
              pkg[48]=new String("javax.swing.");
              pkg[49]=new String("javax.swing.border.");
              pkg[50]=new String("javax.swing.colorchooser.");
              pkg[51]=new String("javax.swing.event.");
              pkg[52]=new String("javax.swing.filechooser.");
              pkg[53]=new String("javax.swing.plaf.");
              pkg[54]=new String("javax.swing.plaf.basic.");
              pkg[55]=new String("javax.swing.plaf.metal.");
              pkg[56]=new String("javax.swing.plaf.multi.");
              pkg[57]=new String("javax.swing.table." );
              pkg[58]=new String("javax.swing.text.");
              pkg[59]=new String("javax.swing.text.html.");
              pkg[60]=new String("javax.swing.text.html.parser.");
              pkg[61]=new String("javax.swing.text.rtf.");
              pkg[62]=new String("javax.swing.tree.");
              pkg[63]=new String("javax.swing.undo." );
              pkg[64]=new String("javax.transaction." );
              pkg[65]=new String("org.omg.CORBA." );
              pkg[66]=new String("org.omg.CORBA_2_3." );
              pkg[67]=new String("org.omg.CORBA_2_3.portable." );
              pkg[68]=new String("org.omg.CORBA.DynAnyPackage." );
              pkg[69]=new String("org.omg.CORBA.ORBPackage." );
              pkg[70]=new String("org.omg.CORBA.portable." );
              pkg[71]=new String("org.omg.CORBA.TSIdentificationPackage." );
              pkg[72]=new String("org.omg.CORBA.TypeCodePackage." );
              pkg[73]=new String("org.omg.CORBA.ValueDefPackage." );
              pkg[74]=new String("org.omg.CosNaming." );
              pkg[75]=new String("org.omg.CosNaming.NamingContextPackage." );
              pkg[76]=new String("org.omg.SendingContext." );
              boolean found=false;
              int counter=0;
              Class cl;
              String str1=str;
              while(counter<77&&found==false)
                   try
                        System.out.println("searching for "+str1);                    
                        cl=Class.forName(str1);                    
                        found=true;                    
                        if(javaEditor.ClassList.isEmpty())
                             javaEditor.ClassList.add(0,cl);                    
                             Class c=(Class)javaEditor.ClassList.elementAt(0);
                             System.out.println(c.getName());
                        else
                             javaEditor.ClassList.add(javaEditor.ClassList.size(),cl);
                   catch(Exception e)
                        str1=pkg[counter]+str;
                   counter++;
              return ;
    /*############# key_words.java*/
    public class key_words
         public static boolean isKeyWord(String keyword)
              String list[]= new String[48];
              list[0] = "abstract";
              list[1] = "boolean";
              list[2] = "break";
              list[3] = "byte";
              list[4] = "case";
              list[5] = "catch";
              list[6] = "char";
              list[7] = "class";
              list[8] = "const";
              list[9] = "continue";
              list[10] = "default";
              list[47] = "do";
              list[11] = "double";
              list[12] = "else";
              list[13] = "extends";
              list[14] = "final";
              list[15] = "finally";
              list[16] = "float";
              list[17] = "for";
              list[18] = "goto";
              list[19] = "if";
              list[20] = "implements";
              list[21] = "import";
              list[22] = "instanceof";
              list[23] = "int";
              list[24] = "interface";
              list[25] = "long";
              list[26] = "native";
              list[27] = "new";
              list[28] = "package";
              list[29] = "private";
              list[30] = "protected";
              list[31] = "public";
              list[32] = "return";
              list[33] = "short";
              list[34] = "static";
              list[35] = "strictfp";
              list[36] = "super";
              list[37] = "switch";
              list[38] = "synchronized";
              list[39] = "this";
              list[40] = "throw";
              list[41] = "throws";
              list[42] = "transient";
              list[43] = "try";
              list[44] = "void";
              list[45] = "volatile";
              list[46] = "while";
              //list[47] = "do";
              for(int i=0;i<48;i++)
                   if(keyword.equals(list))
                        return true;
              return false;

    If you had seen my code You would have know that i have inserted JList into scroll pane.
    I have added comments before and after that portion of code to make it easy to notice..
    insert your jList into jScrollPane

  • File IO basics more than 1 problem with streams any help?

    Have console program that i've built up in steps from reading args from the command line and displaying the text to now wanting to learn to read and write to a disk file.
    i know i have a number of errors but believe it's down to something i am not understanding with the use of datastreams.
    a snippit of code is below.
      if (args.length > 0)
                // Read what the use has entered and keep for later use
            for (int i=0; i < args.length; i++)
              text = text + args;
    try
    //path is define further up as c:\my projects\
    System.out.print (path);
    //create a file object to point to the file the user has given for reading to
    // the file and another to read the file back in
    File fileIn = new File (path,text);
    // File fileOut = new File (path,text);
    // Not sure if this is required!!
    fileIn.createNewFile();
    // thefileOut.createNewFile();
    //Thought this would be the right way of of creating the stream
    // DataOutputStream thefileIn = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileIn)));
    // DataOutputStream thefileOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileOut)));
    //errors on exists and delete methods
    if (fileIn.exists())
    fileIn.Delete();
    catch(IOException e)
    {            // also errors in the getmessage
    System.out.print("Error occured!"+ fileIn.getmessage());
    the errors i am getting are to do with the DELETE method
    The Getmessage method
    Exits method
    i have others but if i can get help with these then i might be able to fix the others.
    thanks

    complete program code below :)
    import java.io.*;
    public class mysimpleio
      String thefilename = "";
    //  String ToFile(String thefilename);
    //  String FromFile(String thefilename);
      public static void main(String[] args)
        String text = "";
        String path = "e:\\my_project\\crm\\";
        if (args.length == 0)
            System.out.println("No file name, Exiting program!");
        if (args.length > 0)
            for (int i=0; i < args.length; i++)
              text = text + args;
    try
    System.out.print (path);
    File fileIn = new File (path,text);
    // File fileOut = new File (path,text);
    fileIn.createNewFile();
    // thefileOut.createNewFile();
    // DataOutputStream thefileIn = new DataOutputStream(new
    BufferedOutputStream(new FileOutputStream(fileIn)));
    // DataOutputStream thefileOut = new DataOutputStream(new
    BufferedOutputStream(new FileOutputStream(fileOut)));
    if (fileIn.exists())
    fileIn.delete();
    catch(IOException e)
    System.out.print("Error occured!"+ fileIn.getmessage());
    ToFile(text);
    System.out.print("\n okay so you entered "+ text);
    if (!fileIn.exists())
    System.out.println("Sorry no file found matching " + text);
    else
    if (fileIn.exists())
    FromFile(text);
    // put data to a Disk File
    static void ToFile(String thefilename)
    // thefileOut.writeUTF(path);
    System.out.println("Data would be written to file Now! "
    +thefilename);
    //Read data From a Disk File
    static void FromFile(String thefilename)
    fileIn.readUTF(path);
    System.out.println(" Data would be Read From file Now! "
    +thefilename);
    Errors are....
    can not resolve symbol
    E:\my_project\crm>javac mysimpleio.java
    mysimpleio.java:43: cannot resolve symbol
    symbol : variable fileIn
    location: class mysimpleio
    System.out.print("Error occured!"+ fileIn.getmessage());
    ^
    mysimpleio.java:49: cannot resolve symbol
    symbol : variable fileIn
    location: class mysimpleio
    if (!fileIn.exists())
    ^
    mysimpleio.java:53: cannot resolve symbol
    symbol : variable fileIn
    location: class mysimpleio
    if (fileIn.exists())
    ^
    mysimpleio.java:70: cannot resolve symbol
    symbol : variable path
    location: class mysimpleio
    fileIn.readUTF(path);
    ^
    mysimpleio.java:70: cannot resolve symbol
    symbol : variable fileIn
    location: class mysimpleio
    fileIn.readUTF(path);
    ^
    5 errors
    E:\my_project\crm>

  • File CR/LF at the end

    I was trying to read a file from one place and write it to other place in my Windows environment.
    But at the end of each line it is adding a CR/LF, it Should be just LF.
    How can I get rid of it. part of the code is
    public void transferFile(String fromFile, String toFile) {
              try {
                   System.setProperty("line.separator", "\n");
                   FileChannel src= new FileInputStream(fromFile).getChannel();
                   FileChannel dst = new FileOutputStream(toFile).getChannel();
                   dst.transferFrom(src, 0, src.size());
                   src.close();
                   dst.close();
              } catch (IOException e) {
         }thanks,

    Rename would have the same effect, if it worked. The
    OP's posted code just copies the file, byte for byte,
    from one place to another. So if the output file has
    CR/LF in it as line separators, then so did the input
    file.You were right, I was getting a file with CR\LF, mainframe was sending it in ASCII mode.
    They can't change it to binary for other reasons. In my process I'm trying to remove the CR/LF from the file. This is my peace of code, which doesn't seem to work. Does anyone have any ideas?
    try {
                   System.setProperty("line.separator", "\n");
                   FileReader fr = new FileReader(args[0]);
                   BufferedReader br = new BufferedReader(fr);
                   FileWriter fw = new FileWriter(args[1]);
                   PrintWriter pw = new PrintWriter(fw);
                   String line = "";
                   int cr=0;
                   while ((line = br.readLine()) != null) {
                        cr= line.indexOf("\t\n");
                        if(cr > 0){                    
                        line =line.substring(0,cr);                    
                        pw.println(line);
                        cr=0;
                   br.close();
                   fr.close();
                   pw.close();
                   fw.close();
              } catch (Exception e) {
                   e.printStackTrace();
              } thanks,

  • Loading a large number of strings into memory quickly

    Hello,
    I'm working on an iPhone application where I need to load a large number of strings into memory. Currently I'm simply reading from a file where each string is stored in plain text on a single line. I read the file contents into a string using stringWithContentsOfFile and then I create an NSSet object using NSSet setWithArray:[string componentsSeparatedByString:@"\n"]];
    This works like a charm but takes around 8 seconds to load on the iPhone. I'm looking for ways to speed this up. I've already tried a few things which weren't any faster:
    1) I used [NSKeyedArchiver archiveRootObject:myList toFile:appFile]; to store the NSSet data structure. Then instead of reading the text file storage. I read this file using [NSKeyedUnarchiver unarchiveObjectWithFile:appFile]; This was actually very slow and created a strings file that was about 2x the size of the original plain text.
    2) Instead of using an NSSet, I used and NSDictionary and used writeToFile and dictionaryWithContentsOfFile. This was also no faster.
    3) Finally I tried using the NSDictionary to write to a binary file format using NSPropertyListSerialization. This was also not any faster.
    I've been thinking about using SQLite instead of the flat file read, but I haven't had a chance to prototype that out to see if it would be faster. It's important that I can do fast searches for specific strings, which is why I originally used a set.
    Does any one else have any ideas how to load this into memory faster? If all else fails, I'm simply going to load the strings into memory using a separate thread on application launch so I don't prevent the user from getting to the main menu for 8 seconds.
    Thanks,
    -Keith

    I'd need to know more about what you're doing, but from what you're describing I think you should try to change your algorithm.
    For example: Instead of distributing one flat file, split your list of strings into 256 files, based on the first two hex digits of their MD5 hashes*. (Two digits might not be enough--you might need three or four. You may also want to use folders, especially if you need more than two digits.) When testing if a string exists, first calculate its MD5 hash and extract the necessary number of digits, then load that file into memory and scan its list. (You can cache these lists in memory so that you only have to load each file once--just make sure that a didReceiveMemoryWarning message will empty those caches.)
    Properly configured, SQLite may be faster than the eight second load time you talk about, especially if you ensure it indexes the column you store the strings in. But it's probably overkill for this application.
    \* A hash is a numeric code calculated from a string; on average, changing a single bit anywhere in the string should change half the bits in the hash, so even very similar strings should generate very different hashes. I suggest using MD5 instead of -\[NSString hash\] because the hash method is not guaranteed to return the same results on Mac OS and iPhone OS, or on different releases of either OS. You could also use a different algorithm, like a CRC; these are faster but I'm not as familiar with them. This thread discusses calculating MD5 hashes on iPhone OS: http://discussions.apple.com/thread.jspa?messageID=7362074
    Message was edited by: Brent Royal-Gordon

  • Cannot assign an empty string to a parameter with JDBC type VARCHAR

    Hi,
    I am seeing the aforementioned error in the logs. I am guessing its happening whenever I am starting an agent instance in PCo. Can somebody explain whats going on?
    Regards,
    Chanti.
    Heres the complete detail from logs -
    Log Record Details   
    Message: Unable to retreive path for , com.sap.sql.log.OpenSQLException: Failed to set the parameter 1 of the statement >>SELECT ID, PARENTID, FULLPATH, CREATED, CREATEDBY, MODIFIED, MODIFIEDBY, REMOTEPATH, CHECKEDOUTBY FROM XMII_PATHS WHERE FULLPATH =  ?  <<: Cannot assign an empty string to a parameter with JDBC type >>VARCHAR<<.
    Date: 2010-03-12
    Time: 11:32:37:435
    Category: com.sap.xmii.system.FileManager
    Location: com.sap.xmii.system.FileManager
    Application: sap.com/xappsxmiiear

    Sounds like a UI browsing bug (when no path is selected from a catalog tree folder browser) - I would suggest logging a support ticket so that it can be addressed.

  • Problems with string comparison and\or If statement

    Right now I'm trying to make a program that will look into all of my music folders, and rename the .mp3 files to a format i want, based on the id3 tags. The program so far looks in all of the folders I want it to, but I get stuck when I need to check if the files are .mp3 files or not. Here is my code so far:
    package fileRenamer;
    import java.io.File;
    public class FileRenamer {
    public static void main(String[] argv) {
         File artistsFolders = new File("F:/Music (MP3)");
         File[] artists = artistsFolders.listFiles();
         for(int i = 0; i < artists.length; i++){
              if(artists.isFile()) {
                   System.out.println(artists[i].getName());
         } else if (artists[i].isDirectory()) {
              System.out.println(artists[i].getName());
              File albumsFolders = new File("F:/Music (MP3)/"+artists[i].getName());
              File[] albums = albumsFolders.listFiles();
              for(int a = 0; a < albums.length; a++){
                   if(albums[a].isFile()) {
                        System.out.println("-" + albums[a].getName());
                   } else if (albums[a].isDirectory()) {
                        System.out.println("-" + albums[a].getName());
                   File songsFolders = new File("F:/Music (MP3)/"+artists[i].getName()+"/"+albums[a].getName());
                   File[] songs = songsFolders.listFiles();
                   for(int s = 0; s < songs.length; s++){
                        if(songs[s].isFile()) {
                             int dotPos = songs[s].getName().toString().lastIndexOf(".");
                             String extension = songs[s].getName().toString().substring(dotPos);
                             System.out.println(extension);
                             if(extension == ".mp3"){
                                  System.out.println("--" + songs[s].getName());
                   } else if (songs[s].isDirectory()) {
                             System.out.println("--" + songs[s].getName());
    When I test the code, the line System.out.println(extension); prints .mp3 into the console for all of the .mp3 files. Whatever I try, the if(extension == ".mp3") never seems to declare the two equal. If anyone knows what my problem is, I greatly appreciate the advice and help.
    Thanks in Advance,
    James

    Pojo226 wrote:
    I just tried that and it worked perfectly. Thanks.You're welcome.

  • Oracle, Null and empty Strings

    Currently I'm facing problems with a class, which contains a String, which
    is set to "" (empty String).
    When the class is persistent, oracle writes null to the table column
    (which seems to be common oracle behaviour) and when retrieving the class,
    the field is set to null as well, giving me a lot of null-pointer
    exceptions.
    Anyway ... I can cope with that (just a lot of extra work)
    far worse is the problem, wenn searching objects, that have this field set
    to "" oder null.
    Oracle can't find the records because JDO creates Querys "where
    string=null" or "where string=''" , where oracle expects "where string is
    null" to find the records.
    Is there a workaround or solution ?

    Yeah, that would work as well, thx, but since I have to cope with
    null-Strings now everywhere in my program, it doesn't hurt just to forbid
    empty strings on the program side.
    In future times I'll test on Oracle first, then porting to DB/2 - this way
    I suppose work is far less to garant compability.
    Nevertheless ... having to set the bankcode into quotes is a kodo bug in
    my opinion.
    Kodo knows the type of classfields (in this case string) and shouldn't
    send the parameter as a BigDecimal to the database.
    Given that, and having only bankcodes of null (only neccesary when using
    Oracle), the method would look like:
    public Collection getAccounts (String bankCode)
    throws Exception
    return getAccounts (Account.class, "bankcode=="+bankcode);
    which is how a transparent persistent layer, um, should be , um , I mean
    ... just transparent ;-D
    Marc Prud'hommeaux wrote:
    Stefan-
    Couldn't you just do something like:
    public Collection getAccounts (String bankCode)
    throws Exception
    String filter;
    if (bankCode == null || bankCode.length () == 0)
    filter = "(bankCode == null || bankCode == "")";
    else
    filter = "bankCode == "" + bankCode + """;
    return getAccounts (Account.class, filter);
    If I understand the problem correctly, this should work for all the
    databases.
    In article <[email protected]>, Stefan wrote:
    What operations are you performing to cause this SQL to be issued? You
    say you are having trouble removing objects, but this is clearly not a
    DELETE statement. Is this the SQL that is issued when looking up
    objects by identity?I'm not removing objects, I was removing just quotes from parameters ;-)
    A string column... is it also represented as a string field in your class?Yeah ... just to give you an impression of the code:
    First we have a class, representing a bank account:
    public class Account {
    private AccountMgr myAccountMgr;
    private String bankCode;
    private String id;
    Note, that in nearly all cases bankCode will be a number or null.
    I have a second class "AccountMgr", which does all of the persistant stuff
    (seaching, making persistent etc.)
    This class has two methods, one versatile (protected) to retrieve accounts
    by a given filterString and one who just returns accounts by bankCode,
    building the expected filterstring. Here is my current working version:
    public class AccountMgr {
    public Collection getAccounts(String bankCode) throws Exception {
    if (bankCode!=null) {
    if (bankCode.equals("")) {
    throw new Exception("check code, bankCode='' not allowed to get
    same behavior from DB2 and Oracle");
    // if set, quote the bankCode
    bankCode="""+bankCode+""";
    return getAccounts(Account.class,"bankCode=="+bankCode);
    protected Collection getAccounts(Class accountClass, String filterAdd)
    throws Exception {
    PersistenceManager pm = MyHelper.getPersistenceManager();
    String filter="";
    if (filterAdd!=null && !filterAdd.trim().equals("")) {
    filter+=filterAdd + " && ";
    filter += "myAccountMgr==_accMgr";
    Query query = pm.newQuery(accountClass, filter);
    query.declareParameters("AccountMgr _accMgr");
    return (Collection) query.execute(this);
    As you can see, in the first method I have to set the bankCode into
    quotes, when it's not null.
    This is because otherwise a filter like "bankCode=1234" will be translated
    in a way, where 1234 is send as a BigDecimal to the database:
    [...] executing statement <4239745>: (SELECT [...] FROM JDO_ACCOUNT t0
    WHERE t0.BANKCODE = ? : [reused=1;params={(BigDecimal) 1234}]
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • NULL and Empty String

    Hi There,
    As far as I know, Null is not the same as an empty string; however, when I try this out, I get some unexpected results (well, at least unexpected for my liking):
    SQL> CREATE TABLE TS (MID NUMBER,
      2  MDESC VARCHAR2(20) DEFAULT '' NOT NULL);
    Table created.
    SQL> INSERT INTO TS VALUES(1,'');
    INSERT INTO TS VALUES(1,'')
    ERROR at line 1:
    ORA-01400: cannot insert NULL into ("TT"."TS"."MDESC")So, according to the above scenario, I can't insert an empty string!! However, an empty string is a valid string that doesn't have tuples/data!!
    How come Oracle translates the null string '' as NULL?
    Thanks

    William Robertson wrote:
    There is a special case to do with CHAR values, whereby '' counts as a string and so gets blank-padded, whereas NULL does not.Are you referring to:
    SQL> DECLARE
      2      flag CHAR(2);
      3      PROCEDURE check_null (p_flag IN CHAR)
      4      IS
      5      BEGIN
      6        IF p_flag = '  '
      7        THEN
      8          dbms_output.put_line ('flag is equal to ''  ''');
      9        ELSIF p_flag IS NULL
    10        THEN
    11          dbms_output.put_line ('flag is null');
    12        ELSE
    13          dbms_output.put_line ('other');
    14        END IF;
    15      END;
    16    BEGIN
    17      flag := '';
    18      check_null (flag);
    19      flag := NULL;
    20      check_null (flag);
    21    end;
    22  /
    flag is equal to '  '
    flag is null
    PL/SQL procedure successfully completed.
    SQL> alter session set events '10932 trace name context forever, level 16384';
    Session altered.
    SQL> DECLARE
      2      flag CHAR(2);
      3      PROCEDURE check_null (p_flag IN CHAR)
      4      IS
      5      BEGIN
      6        IF p_flag = '  '
      7        THEN
      8          dbms_output.put_line ('flag is equal to ''  ''');
      9        ELSIF p_flag IS NULL
    10        THEN
    11          dbms_output.put_line ('flag is null');
    12        ELSE
    13          dbms_output.put_line ('other');
    14        END IF;
    15      END;
    16    BEGIN
    17      flag := '';
    18      check_null (flag);
    19      flag := NULL;
    20      check_null (flag);
    21    end;
    22  /
    flag is null
    flag is null
    PL/SQL procedure successfully completed.
    SQL> SY.
    P.S. Don't ask me why normal (or at least consistent) behavior is not the default.

  • Null and empty string not being the same in object?

    Hello,
    I know that null and empty string are interpreted the same in oracle.
    However I discovered the strange behaviour concerning user defined objects:
    create or replace
    TYPE object AS OBJECT (
    value VARCHAR2(2000)
    declare
    xml xmltype;
    obj object;
    begin
    obj := object('abcd');
    xml := xmltype(obj);
    dbms_output.put_line(xml.getStringVal());
    obj.value := '';
    xml := xmltype(obj);
    dbms_output.put_line(xml.getStringVal());
    obj.value := null;
    xml := xmltype(obj);
    dbms_output.put_line(xml.getStringVal());
    end;
    When creating xml from object, all not-null fields are transformed into xml tag.
    I supposed that obj.value being either '' or null will lead to the same result.
    However this is output from Oracle 9i:
    <OBJECT_ID><VALUE>abcd</VALUE></OBJECT_ID>
    <OBJECT_ID><VALUE></VALUE></OBJECT_ID>
    <OBJECT_ID/>
    Oracle 10g behaves as expected:
    <OBJECT><VALUE>abcd</VALUE></OBJECT>
    <OBJECT/>
    <OBJECT/>
    However Oracle 9i behaviour leads me to the conclusion that oracle
    must somehow distinguish between empty string and null in user defined objects...
    Can someone clarify this behaviour?
    Thus is it possible to test if object's field is empty or null?

    However Oracle 9i behaviour leads me to the conclusion that oracle
    must somehow distinguish between empty string and null in user defined objects...
    Can someone clarify this behaviour?
    Thus is it possible to test if object's field is empty or null?A lot of "fixes" were done, relating to XML in 10g and the XML functionality of 9i was known to be buggy.
    I think you can safely assume that null and empty strings are treated the same by Oracle regardless. If you're using anything less than 10g, it's not supported any more anyway, so upgrade. Don't rely on any assumptions that may appear due to bugs.

  • Difference in Null and Empty String

    Hi,
    I have been wondering about the difference between Null and Empty String in Java. So I wrote a small program like this:
    public class CompareEmptyAndNullString {
         public static void main(String args[]) {
              String sNull = null;
              String sEmpty = "";
              try {
                   if (sNull.equalsIgnoreCase(sEmpty)) {
                        System.out.println("Null and Empty Strings are Equal");
                   } else {
                        System.out.println("Null and Empty Strings are Equal");
              } catch (Exception e) {
                   e.printStackTrace();
    This program throws Exception: java.lang.NullPointerException
         at practice.programs.CompareEmptyAndNullString.main(CompareEmptyAndNullString.java:10)
    Now if I change the IF Clause to if (sEmpty.equalsIgnoreCase(sNull)) then the Program outputs this: Null and Empty Strings are Equal
    Can anyone explain why this would happen ?
    Thanks in Advance !!

    JavaProwler wrote:
    Saish,
    Whether you do any of the following code, the JUnit Test always passes: I mean he NOT Sign doesnt make a difference ...
    assert (! "".equals(null));
    assert ("".equals(null));
    You probably have assertions turned off. Note the the assert keyword has nothing to do with JUnit tests.
    I think that older versions of JUnit, before assert was a language keyword (which started in 1.4 or 1.5), had a method called assert. Thus, if you have old-style JUnit tests, they might still compile, but the behavior is completely different from what it was in JUnit, and has nothing to do with JUnit at all.
    If you turn assertions on (-ea flag in the JVM command line, I think), the second one will throw AssertionError.

Maybe you are looking for

  • Conexant Audio Speakers No Longer Working After Unplugging Headphones - X301

    Hello, I plugged in some headphones via the jack for the first time after owning my X301 for 2 months.  Ever since then, the laptop speakers stopped working!!!  If I want to hear anything, I now have to listen via my headphones.  The beeping I used t

  • Particular case of Key calculation in invoice

    Hi guys, I have a particular case in which I don't understand how the system calculates WRX and EIN keys in Invoice:I describe an example semplyfing the numbers 1) I have a PO with quantity ordered = 100 and price order 10: I entered several GR for a

  • Firmware Update Failure? Extreme help needed

    I was trying to update my ipod but when i tried to restore it, it suddenly stopped, then it said firmware update failure. No my ipod is screwed up again. This is the second time. The first time i sent it away and they gave me a new one, i followed th

  • Grant privilges ON schema

    Hi, We hava created user user01, could you please advise how to grant create table and select privileges to that user on another schema. Thanks

  • My bookmarks toolbar is gone & won't come back, how do I get it back?

    I have already googled the problem & have tried all of the suggested fixes. When I click on the "Show your bookmarks" icon in the upper right, I can click on "Bookmarks Toolbar" and I can see the bookmarks in a list, but they are no longer on a bar n