c**t 发帖数: 2744 | 1 I was pulling my hair out while try to resolve the follow exception
using(StreamWriter sw = new StreamWriter(fileName, false))
{
sw.Write(someString);
sw.Close();
};
it's because the fileName has ':' in it!! great bug!!
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path,
Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(
String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(
Fi |
|
q*****z 发帖数: 191 | 2 Hi,
I am new to .net but have used c for years. I met a problem recently using .
net C++. What I want to do is to use openFileDialog() to open a file and
write some binary information to it. Here is what I have:
SaveFileDialog^ d = gcnew SaveFileDialog;
d->Filter = "exp files (*.exp)|*.exp";
if (d->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
FILE *fid;
fopen(fid,d->FileName,'wb+');
fwrite(buf,1,frameSize,fid);
fclose(fid);
}
It seems like d->Filename does't return the standard st |
|
s*****w 发帖数: 215 | 3 I also tested the above code,
multiple files are downloaded,
wc.DownloadFile(url, filename); the second parameter is the filename you are
going to download to. For each thread, they should have their own file
names. |
|
r****y 发帖数: 26819 | 4 如果是我,会另外写一个程序,python或者c#,每次添加照片以后,运行一遍那个程序
生成包含文件名的xml文件,然后flash读取这个xml。比如这个xml可以是:
pic1.jpg
XX_XX_XXXX
This is some pic taken where
...
...
省事的话,一个script程序就可以,也可以拿c#做个简单界面,一边浏览照片,给每个
照片添加文字description。这样信息足够做一个album了。 |
|
r****y 发帖数: 26819 | 5 如果是我,会另外写一个程序,python或者c#,每次添加照片以后,运行一遍那个程序
生成包含文件名的xml文件,然后flash读取这个xml。比如这个xml可以是:
pic1.jpg
XX_XX_XXXX
This is some pic taken where
...
...
省事的话,一个script程序就可以,也可以拿c#做个简单界面,一边浏览照片,给每个
照片添加文字description。这样信息足够做一个album了。 |
|
l******n 发帖数: 1683 | 6 刚才拿了一个1.5G的文件测试了一下(系统内存8G), 直接sort filename
没有cat filename | sort快. |
|
|
xt 发帖数: 17532 | 8
On 2nd though, I didn't. Here's the method "readFile":
public static byte[] readFile( String fileName ) throws
FileNotFoundException, IOException
{
byte[] buff=null;
// Read in the file content
InputStream in=null;
try{
in = new FileInputStream( fileName );
buff = new byte[in.available()];
in.read( buff );
} finally {
if( in!=null ) {
try{
in.close();
} catch ( Exception e ) {
// Ignore
}
}
}
return buff;
} |
|
o*******r 发帖数: 3 | 9 JimiRasterImage jrf
= Jimi.createRasterImage( );
if (fileType == 1)
{
Jimi.putImage("image/jpg", jrf,
new FileOutputStream(fileName));
}
else if (fileType == 3){
Jimi.putImage("image/png", jrf,
new FileOutputStream(fileName));
} |
|
m*****k 发帖数: 731 | 10 can you create a hiden field on the page to store the filename? the at
server side you use request.getParameter() to get the filename? |
|
s******e 发帖数: 493 | 11 A jquery version of file upload.
$(document).ready(function() {
$("#uploadbutton").click(function() {
var filename = $("#file").val();
$.ajax({
type: "POST",
url: "addFile.do",
enctype: 'multipart/form-data',
data: {file: filename},
success: function(){
alert( "Data Uploaded: ");
}
});
});
}); |
|
b***i 发帖数: 3043 | 12 某个类的文件本地读入和处理需要0.5秒,我就想能不能串行化,然后我直接读入。结
果发现,直接本地读入object需要1秒。下面就是代码,请问有没有办法加速?obj文件
一共几百k bytes.
public static Object load(String filename){
try {
FileInputStream fin = new FileInputStream(filename);
ObjectInputStream ois = new ObjectInputStream(fin);
Object obj = ois.readObject();
ois.close();
System.out.println("unserialized theQueue");
return obj;
} catch (Exception e) { e.printStackTrace(); }
return null;
} |
|
y****e 发帖数: 1012 | 13 cache.csv was created in class DataCache.
public class DataCache {
private static final String FILENAME = "cache.csv";
private static final double TOLERANCE = 0.1;
private static List memCacheCoord = new ArrayList<
Coordinate>()
;
private static List memCacheConte = new ArrayList();
.....
public static void addValue(double lat, double lng, Object data) {
try {
DecimalFormat format = new De... 阅读全帖 |
|
a****i 发帖数: 1182 | 14 程序有点搞笑
do {
System.out.println("File exists! Enter a different name:");
fileName=keyboard.nextLine();
--> tester = new File (path + fileName);
} while(tester.exists()); |
|
u****a 发帖数: 1098 | 15 遇到一个非常奇怪的问题..
在server上用perl进行文件处理,输出结果保存在.txt文件...
结果每个.txt输出文件都是这种格式: filename?.txt
试过 chmod 777 filename?.txt
依旧无法下载..
在winSCP下的话根本打不开,提示os function错误..
请知道的帮助一下..
只是想把运行结果保存下来...
非常非常谢谢.. |
|
Z**0 发帖数: 1119 | 16 scp server:filename . (from server to localhost)
scp filename servername:. (from localhost to server) |
|
b****l 发帖数: 95 | 17 如何在没有admin权限的windows xp机器下做到以下的batch process.
Given a list of files (each file name is a line) in names.txt file:
for each filename in the list, run (in the order specified)
awk 'NR>1' filename >> concatenated.txt
BTW 没法安装perl/python 但可以下载 awk for windows。想dos shell,但不会用。
Thanks a lot! |
|
D***h 发帖数: 78 | 18 for i in *; do (filename=$(head -1 $i); mv $i $filename); done |
|
l******n 发帖数: 1683 | 19 split呀, 比如如果文件是千万行这个级别的话, 下面这样就可以了
split -l 10000 -d -a 4 filename filename
分割后的文件命名filename0000, filename0001, ... |
|
d********g 发帖数: 10550 | 20 这是override constructor,new style的class,super class就是object。没规定一
定要super,如果你不要基类的constructor的话。不光是__init__(),任何method都是
这个道理,要扩展(重用之前的代码)就是super,不super就是直接覆盖
因为object本身是不接收args、kwargs的所以可以这样简写,如果是从别的有可能接受
args的class继承,为了安全一般还得这样写:
class Reader(BaseClass):
def __init__(self, filename=None, *args, **kwargs):
super(Reader, self).__init__(*args, **kwargs)
# 然后再处理你自己的filename
Python 3里可以把super(Reader, self)简化成super() |
|
d********g 发帖数: 10550 | 21 这是override constructor,new style的class,super class就是object。没规定一
定要super,如果你不要基类的constructor的话。不光是__init__(),任何method都是
这个道理,要扩展(重用之前的代码)就是super,不super就是直接覆盖
因为object本身是不接收args、kwargs的所以可以这样简写,如果是从别的有可能接受
args的class继承,为了安全一般还得这样写:
class Reader(BaseClass):
def __init__(self, filename=None, *args, **kwargs):
super(Reader, self).__init__(*args, **kwargs)
# 然后再处理你自己的filename
Python 3里可以把super(Reader, self)简化成super() |
|
s*****w 发帖数: 1527 | 22 假如说我有一个程序,让用户输入一个文件,然后存成带有日期的文件名,
myProgram filename
得到
filename + "." + Date.now()
那么不同用户可能输入同样文件名,我希望timestamp可以区分它们。
请问可以吗? |
|
f********u 发帖数: 572 | 23 ifstream in;
string filename[2] = {"a.txt", "b.txt"};
while (in) {
int j;
in.open (filename[j], ios::in);
j++;
}
编译错误。请问我错在哪里了? |
|
c******n 发帖数: 4965 | 24 又一个衰人写的程序, 要拿来用,
出segfault
我就拼命查,
gdb where 出来看居然事malloc() 自己segfault
library 怎么会出错那???
幸好有另外一个地方出绰,一个文件名最后的一个子母
编成乱码了,
怎么会这样呢? 就在程序里加了一个全程变量,
进入,stop,
set my_new_var=changed_char_of_filename
然后watch my_new_var
结果是那个malloc() 开到了filename 上了,
再一看,这个衰人给filename 最开始malloc() 的地方缺\000
ft to death
then afterwards, got another strange segfault with malloc()
this time I have not idea who was writing into unallocated space,
so I had to use valgrind,
it was pretty cool, turns out it was the same stupid err |
|
b*********n 发帖数: 1258 | 25 想利用别人定义好的一个程序
int* LinearSuffixSort(char*& inputString, int& stringLength);
inputString is the pointer to the string to be sorted. stringLength is the l
ength of inputString.
===================
我的程序是这样的
#include "LinearSuffixSort.h"
using namespace std;
void main(int argc, char* argv[]){
char * fileName="abcdefg";
cout << LinearSuffixSort(fileName,7) << endl;
}
===================
Compile不通过
error C2665: 'LinearSuffixSort' : none of the 3 overloads can convert parame
ter 1 from type 'char *'
== |
|
h*******s 发帖数: 11 | 26 来自主题: Programming版 - awk求救 I don't know about Cygwin, but gawk needs a flag:
gawk --posix "/a{2}/"
gawk --re-interval "/a{2}/" |
|
J*******3 发帖数: 1651 | 27 在用c写程序时,很多时候需要存储一些简单的数据,如果为此而用mysql数据库就有些
大才小用了,可以把这些数据以结构的形写入文件,然后再需要时读取文件,取出数据。
如下是定义函数的源文件和头文件:
源文件struct.c:
#include "struct.h"
//第一个参数是要写入的文件名,第二个参数是缓冲区,第三个参数是缓冲区大小,
第四个参数是打开文件流的形态,返回TRUE表示写入成功,返回FALSE表示写入失败
int writeStruct(const char *fileName,char *buffer,int bufferLen,char *mode){
int ret;
FILE *fileID = NULL;
fileID = fopen(fileName,mode);
if (fileID == NULL){
perror("fopen");
goto writeEnd;
}
rewind(fileID);
ret = fwrite(buffer,bufferLen,1,fi |
|
i**p 发帖数: 902 | 28 I don't think this answer is right. We can use open("filename", "r") too.
116. How can we open a image file through C program
In C, generally we can open files having text format...
other types of files can be opened in binary format only using
file *fp;
fp=fopen("filename","rb+");// where b stands for binary format |
|
c*********n 发帖数: 128 | 29 You need to write a mexFunction() as the interface, just like main()
function as the interface of the program and the calling environment.
Use mex to compile the codes and call the filename including mexFunction()
within Matlab just like the filename is a Matlab function. |
|
H***a 发帖数: 735 | 30 我用下面这段code读的,请指教,谢谢!
for procID=0:(numProcs-1)
fileName = sprintf('%d-DATA.dat', procID);
data = fopen(fileName, 'r');
if data ~= -1
numFreqs = fread(data, 1, 'long');
numLocations = fread(data, 1, 'long');
for m=1:numLocations
x = fread(data, 1, 'long') + 1;
y = fread(data, 1, 'long') + 1;
z = fread(data, 1, 'long') + 1;
for w=1:numFreqs
re = fread(data, 1, 'double');
|
|
t****t 发帖数: 6806 | 31 嗯, 这回我看明白了
可以这样写
for procID=0:(numProcs-1)
fileName = sprintf('%d-DATA.dat', procID);
data = fopen(fileName, 'r');
if data ~= -1
numFreqs = fread(data, 1, 'long');
numLocations = fread(data, 1, 'long');
pos=ftell(data);
xyz=fread(data, [3 numLocations], "3*long", numFreqs*3*2*8)+1;
fseek(data, pos+3*4, -1);
dataformat=sprintf('%d*double', 2*3*numfreqs);
Exyz=fread(data, [2 3*numfreqs*numLocations], dataformat, 3*4);
Exyz=complex(Exyz(1,:), Exyz(2,:));
Exyz=reshape(Exyz, [numFreqs 3 numLocations] |
|
H***a 发帖数: 735 | 32 感谢thrust提供的优化,感谢kkff在“Matlab处理数组一问”这贴中回复教了俺
sub2ind这个无比好用的函数,现在程序优化如下。
测试结果:耗时8秒。非常赞!
Ex = zeros(numFreqs,sizeX,sizeY,sizeZ);
Ey = zeros(numFreqs,sizeX,sizeY,sizeZ);
Ez = zeros(numFreqs,sizeX,sizeY,sizeZ);
for procID=0:(numProcs-1)
fileName = sprintf('%d-NearFieldDFT.dat', procID);
data = fopen(fileName, 'r');
if data ~= -1
numPoints = fread(data, 3, 'int');
totNumPoints = numPoints(1)*numPoints(2)*numPoints(3);
xyz=fread(data,[3 totNumPoints],'int |
|
n**d 发帖数: 9764 | 33 How do we use System V Semaphores for unrelated processes (not forked one)?
Some example code uses Ftok("filename" ...) to generate the key. So if the 2
processes use the same filename then they can get the same key.
More often, we use IPC_PRIVATE for the key. In this case, how can the 2
processes get the same key? Does that mean we have to use Ftok() if we want
to use Sys V Semaphores for 2 unrelated processes? |
|
j****h 发帖数: 6 | 34 Hi:
I am on an aspx.vb code behind. need to make a side request which
returns (I believe a stream of) xml reponse.
Below are my sample codes
Dim excel As New CapitalIQ.Excel.Web.GetData()
Dim context As System.Web.HttpContext
Dim filename As String = String.Empty
Dim url As String = String.Empty
Dim queryString As String = String.Empty
'will initialize filename, url, querystring later
Dim request As New Sys |
|
b***i 发帖数: 3043 | 35 unix/linux, 64位
文件大约几百兆,要读入2维矩阵中,大约几万列,几千行。
原始文件每行格式为
/path...../filename authorname n1, n2, ............, nlast
每行以unix换行符结尾。
我首先要把前面的path基本忽略,可以留下filename, authorname读入到一个vector中,然后把剩下的写入处理过的文件中,只有整数,即每行只有n1, n2到最后一个,每行内的数字用逗号隔开,行间用unix换行符。在这个过程中,可以把总行数搞定,也知道每行多少个数据。然后动态分配数组。
下面就是如何快速读入处理过的文件?我用getline
for(int i=0;i
{
string onenumber;
getline(iss, onenumber, ',');
istringstream(onenumber)>>RawM[j][i];
}
有特别快的办法吗? |
|
W*W 发帖数: 293 | 36 附一下 其中函数的定义:
#include "AVW_ImageFile.h"
AVW_ImageFile *AVW_OpenImageFile(filename, modes)
char *filename;
char *modes; |
|
d****e 发帖数: 251 | 37 dlmread will do the job of "option 1"
dist_matrix = dlmread('filename') % by default the delimiter is whitespace
% ignore first column
dist_matrix = dlmread('filename',' ',0,1) |
|
c****f 发帖数: 1102 | 38 chmod 700 filename
chown user:whatevergroup filename |
|
z****e 发帖数: 2024 | 39 用pipe吧?
open
print
close
#!/usr/bin/perl
use Carp;
$filename=@ARGV[0];
open GEN, '|'.'yourprogramname' or croak "yourprogramname:run -> Starting `yourscriptname` failed";
print GEN $filename,"\n";
close GEN or croak "yourprogramname::run -> Executing 'yourscriptname` failed"; |
|
D*******a 发帖数: 207 | 40 比如在python程序里面产生了个复杂的变量,list里面套list的,想保存在文件里,然
后后续的python程序只需要load这文件,便重新产生了这个变量。如果第一个程序用
txt方式写到文件里,则第二个程序又需要split,费时费力,还容易出错。如果有这样
的命令,在第一个程序里save("filename",list_of_variable_names),然后在第二个
程序里load("filename"),则好很多。问题是有没有呢? |
|
l*******G 发帖数: 1191 | 41 The following works :
#!/bin/bash
filename=`basename $0`
echo "script name is:" $filename |
|
c******2 发帖数: 957 | 42
您用的版本是不是和我不一样的?我的是python3.2
因为我输进去之后,有好些地方说SyntaxError: inconsistent use of tabs and
spaces in indentation不知道是怎么回事呀。。。
如果有时间,能不能麻烦您也帮忙看看我和同学讨论出来的还是有错误的一段代码:
def main():
print("Please input the filename to read: ")
f2read=input()
print("Please input the filename to write: ")
f2write=input()
f1=file(f2read, "r")
f2=file(f2write, "w")
def acronym(string):
p=string.split("")
for word in p:
s+=(word[0].upper())
return s
lines=f1.rea... 阅读全帖 |
|
b********a 发帖数: 5418 | 43 可以build,但是debug就会报这个错:
System.IO.FileLoadException was unhandled
Message: Could not load file or assembly 'filename, Version=1.0.4566.26601,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
所有这些c#,c++ project都是一个solution下面的。以前用一样的方法没问题,中间电
脑崩溃过重装过一次,再从tfs下了代码,就不行了。电脑是x64, .net 3.5.
google出的解决方法完全不适用,那个要删除清空的文件夹根本在我电脑上就不存在,
google如下:
http://blkarwasara.blogspot.com/2011/07/hresult-0x80070057-einv
还尝试了... 阅读全帖 |
|
y****n 发帖数: 15 | 44 下面是一段10行的小程序,调用OpenCV2.1
#include "cv.h"
#include "highgui.h"
#include
using namespace std;
void main()
{
string videofname = "E:\\Demo\\test.avi";
cv::VideoCapture capture;
capture.open(videofname);
cv::Mat frame;
capture >> frame;
}
这个程序在Visual Studio 2008下面编译和运行都正常。
但在VS 2010和VS 2012下运行时,执行到capture.open()产生异常。
追踪到VideoCapture::open(const string& filename)函数内部,发现这时的
filename string就变成了Bad Ptr。
大家有没有遇到过类似的问题?该怎么解决? |
|
l********a 发帖数: 1154 | 45 可能想获取所有文本文件,但是用.txt in filename不是个好办法,因为可能有文件名叫
1.txt.abc,这样也会被选出来.用filename.endswith('.txt')好点儿 |
|
o**2 发帖数: 168 | 46 上周 cplus2009 同学有个问题(http://www.mitbbs.com/article_t/Programming/31253813.html),涉及到GUI程序中线程之间转换的问题。就是controls都要在UIthread(Swing或SWT)里操作,而后台的logic要在非UIthread里操作。
我当时说了FMP可以轻易淘汰掉这种thread-base的编程技术,于是趁这个长周末,把对
UIthread的支持做进了FMP。想要试用的,可以在此download 2.0 jar:https://
github.com/fastmessenger/RI-in-Java/blob/master/fmp-2.0-bin.jar?raw=true
这里我借用 cplus2009 同学的问题作为范例:他的问题是有一个界面,上面有一个
BROWSE按钮,按了后弹出一个文件选择对话框。用户选好文件后,将文件名显示在
BROWSE按钮前面的text里。这里文件选择用来代表后台的耗时操作。
用FMP的,可以这样设计:一个Frontend class用来access UI controls... 阅读全帖 |
|
s****a 发帖数: 6521 | 47 $f = 'file name.txt'
copy('file name.txt','filename.txt'); ##没问题;
copy($f,'filename.txt'); 就有warning : The first argument to copy() function
cannot be a directory
肿莫破? |
|
i***r 发帖数: 1035 | 48 代码:
import sys
pop=98
def ped(genotype):
if genotype=='00':
ped='1 1 '
elif genotype=='01':
ped='1 2 '
elif genotype=='10':
ped='2 1 '
elif genotype=='11':
ped='2 2 '
else:
ped='0 0 '
return ped
def write_ped(filename,out):
fn=open(filename,'r')
fn_ped=open(out+'.ped','w')
fn_map=open(out+'.map','w')
modern_human=range(9,93) # 15+69
for ind in modern_human:
ind_genotype=''
fn.seek(0,0)
for line in fn.readlines():
lis=line[:-1].split("\t... 阅读全帖 |
|
z****e 发帖数: 54598 | 49 为什么那么在意主流?
js是主流?
vert.x就可以给你搞python
import vertx
server = vertx.create_http_server()
@server.request_handler
def handle(req):
filename = "index.html" if req.uri == "/" else req.uri
req.response.send_file("webroot/" + filename)
server.listen(8080)
http://en.wikipedia.org/wiki/Vert.x |
|