Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating output to a file in a single column

 
ric stewart
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create an output file with a single column of data. What I'm using now creates one huge string in my output file:

outFile = File.new("C:/my_ruby_code/output_file.txt", "w")
myFile.each do |element|
outFile.syswrite(element)
end
outFile.close

I've a idea that I should be using print_f with some kind of formatting but I can not find an example anywhere. Any help? Thanks!
 
Steve Nicholson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try appending a newline to entry?
 
ric stewart
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve - Part of my purpose for writing a routine for scrubbing files is to avoid using these two offenders \n \r . Here's what works so far:

myFile = Array.new
myFile =File.readlines("C:/my_ruby_code/list_of_php_array_functions.txt")
myFile.collect! {|element| element.strip}
myFile.collect! {|element| '"'+element+'"'} # I'm adding double quotes so these elements can get stuffed into a php array

File.open("C:/my_ruby_code/output_file.txt", "w") do |line|
line.puts myFile
end

 
Steve Nicholson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Offenders?"

How on earth do you plan on putting each entry on a single line without the proper line delimiters?

puts works because it places the "offender" at the end of the line.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic