Zero size of file created

I’m trying to copy Constant(text,JavaScript) into an external directory.
Strangely, it was okay to do that for ‘awk’ scripts and ‘html’ files but for the JavaScript file, the file is created but the size is zero.
Is there anything I’m missing?

  FileName = FileName + ".js"
  Dim Documents As FolderItem = SpecialFolder.ApplicationData
  
  If Documents <> Nil Then
    
    Dim f As FolderItem = Documents.Child(FileName)  
    
    If f <> Nil Then
      Try
        
        Dim t As TextOutputStream = TextOutputStream.Create(f)
        Dim FindConstantName As String
        FindConstantName = FileName 
        
        Select Case FindConstantName
        Case "testJavaScript" 
          't.write(ReplaceLineEndings(testJavaScript,EndOfLine.Windows))
          t.write(testJavaScript)

        End Select
        
        t = Nil
      Catch e As IOException
        //handle
      End Try
    End If
  End If
FileName = FileName + ".js"
  Dim destination As FolderItem = SpecialFolder.ApplicationData.child(Filename)
  Dim source As FolderItem = Documents.Child(FileName)  
  dim ok as boolean=false
    If source <> Nil Then
      if source.exists=true then 
          source.CopyFileto(desctination)
          ok=true
     end  if
  end if
  if not ok then msgbox "Could not copy "+filename

Examples in the LangRef

This is shorter… plus I saw no place in your code where your ever read the source file

I use a Constant to keep JavaScript information and want to copy it to external file system when needed.
It means that the JavaScript file doesn’t exist in filesystem first.

I think the example above shows how to copy files on file system.

Based on the code you posted and the description of the results, I can only conclude that your “testJavaScript” case is not being executed. Have you stepped through it in the debugger? What is the value of FindConstantName? Is it what you expect it to be, or is it something else?

Ah…I made a mistake.
I should have used a different variable to get the original filename.
With below code, it works well.

Thanks for your comment!

  Dim ModifiedFileName As String
  ModifiedFileName = FileName + ".js"
  
  Dim Documents As FolderItem = SpecialFolder.ApplicationData
  
  If Documents <> Nil Then
    
    Dim f As FolderItem = Documents.Child(ModifiedFileName)  
    
    If f <> Nil Then
      Try
        
        Dim t As TextOutputStream = TextOutputStream.Create(f)
        Dim FindConstantName As String
        FindConstantName = FileName 

Select Case FindConstantName
        Case "testJavaScript" 
          t.write(ReplaceLineEndings(testJavaScript,EndOfLine.Windows))
          
        End Select
        
        t = Nil
      Catch e As IOException
        //handle
      End Try
    End If
  End If