summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/nlp_ruby/fileutil.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/nlp_ruby/fileutil.rb b/lib/nlp_ruby/fileutil.rb
index e560aae..eb69136 100644
--- a/lib/nlp_ruby/fileutil.rb
+++ b/lib/nlp_ruby/fileutil.rb
@@ -23,14 +23,35 @@ class ReadFile
@f.readlines
end
+ def self.readlines fn, encoding='utf-8'
+ f = ReadFile.new fn, encoding
+ r = f.readlines
+ f.close
+ return r
+ end
+
def readlines_strip
self.readlines.map{ |i| i.strip }
end
+ def self.readlines_strip fn, encoding='utf-8'
+ f = ReadFile.new fn, encoding
+ r = f.readlines_strip
+ f.close
+ return r
+ end
+
def read
@f.read
end
+ def self.read fn, encoding='utf-8'
+ f = ReadFile.new fn, encoding
+ r = f.read
+ f.close
+ return r
+ end
+
def close
@f.close if @f!=STDIN
end
@@ -54,6 +75,12 @@ class WriteFile
@f.write s
end
+ def self.write s, fn, encoding='utf-8'
+ f = WriteFile.new fn, encoding
+ f.write s
+ f.close
+ end
+
def close
@f.close if @f!=STDIN
end