我有这个代码成功写入一个文件:
ofstream outfile (path);
outfile.write(buffer,size);
outfile.flush();
outfile.close();
Run Code Online (Sandbox Code Playgroud)
缓冲区和大小在其余代码中都可以.如何将文件放在特定路径中?
以下代码工作正常:
public static void main(String[] args) {
String userName = "admin";
String password = "s3cret";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.10.45:389/dc=softwaredev,dc=local");
//env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, new String("softwaredev" + "\\" + userName));
env.put(Context.SECURITY_CREDENTIALS, password);
DirContext ctx = null;
NamingEnumeration results = null;
try {
ctx = new InitialDirContext(env);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
results = ctx.search("", "(objectclass=person)", controls);
while (results.hasMore()) {
SearchResult searchResult = (SearchResult) results.next();
Attributes attributes = searchResult.getAttributes();
System.out.println(" Person Common Name = " …Run Code Online (Sandbox Code Playgroud) 我从Github获取数据用于我的应用程序.前两个OAuth步骤没问题,但在第三个中我得到以下错误:"服务器提交了协议违规.Section = ResponseStatusLine ERROR"这是我的代码:
protected String WebRequest(string url)
{
url += (String.IsNullOrEmpty(new Uri(url).Query) ? "?" : "&") + "access_token=" + _accessToken;
HttpWebRequest webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = "GET";
webRequest.ServicePoint.Expect100Continue = false;
try
{
using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
return responseReader.ReadToEnd();
}
catch
{
return String.Empty;
}
}
Run Code Online (Sandbox Code Playgroud)
使用StreamReader对象后程序进入异常,返回错误.如果我遵循这些说明服务器提交了协议违规.Section = ResponseStatusLine ERROR,错误变为"403 forbidden".当Github使用api V2时,与现在不同,这段代码没有问题.因此,不能是.NET限制,而是与Github服务器连接的东西.有什么建议?
这是我的代码:
public class TestConnection {
public static void main(String[] args) {
String password = "s3cret";
Map<String, String> env = new HashMap<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/dc=userdev,dc=local");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
//env.put(Context.SECURITY_PRINCIPAL, "uid="+ username +"cn=users"); // replace with user DN
env.put(Context.SECURITY_PRINCIPAL, "cn=dcmanager,cn=users,dc=userdev,dc=local"); // replace with user DN
env.put(Context.SECURITY_CREDENTIALS, password);
DirContext ctx = null;
try {
ctx = new InitialDirContext();
} catch (NamingException e) {
// handle
}
try {
SearchControls controls = new SearchControls();
controls.setSearchScope( SearchControls.SUBTREE_SCOPE);
ctx.search( "", "(objectclass=person)", controls);
// no need …Run Code Online (Sandbox Code Playgroud) 我有一个简单的功能,如:
private void function(LinkedList<String> a, LinkedList<String> b)
Run Code Online (Sandbox Code Playgroud)
我们已经知道,如果这些参数只是字符串,那么内联传递值会很容易,例如:
function("aaa", "bbb")
Run Code Online (Sandbox Code Playgroud)
但是有没有办法通过内联 LinkedList ?
我试过:
function(["A", "B", "C"], ["A", "B"])
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
例如,在linux-machine中有很多进程.每个人都可以使用系统调用,但通常很少使用.那么,有一种工具或方式可以显示何时使用系统调用以及哪个进程相关联?
我正在使用SHA1来加密一些像密码这样的值.这是我的代码:
String passwd = Membership.GeneratePassword(10, 2);
SHA1 sha = new SHA1CryptoServiceProvider();
byte [] password = sha.ComputeHash(passwd);
Run Code Online (Sandbox Code Playgroud)
但VS返回错误,因为passwd是一个字符串.我必须将密码存储在字节数组中,那么有没有办法解决这个问题?
我有2个帖子.我的目标是第一个终止自己的执行,必须停止另一个线程.可能吗?
我有这个代码:
#include <stdio.h>
#include <pthread.h>
#include <sys/types.h>
void* start1(void* arg)
{
printf("I'm just born 1\n");
int i = 0;
for (i = 0;i < 100;i++)
{
printf("Thread 1\n");
}
printf("I'm dead 1\n");
pthread_exit(0);
}
void* start2(void* arg)
{
printf("I'm just born 2\n");
int i = 0;
for (i = 0;i < 1000;i++)
{
printf("Thread 2\n");
}
printf("I'm dead 2\n");
pthread_exit(0);
}
void* function()
{
int k = 0;
int i = 0;
for (i = 0;i < 50;i++)
{ …Run Code Online (Sandbox Code Playgroud) 我正在为我的程序使用BitSet类.我需要一个内联声明,如:
BitSet bits1 = new BitSet(); //standard declaration
bits1.set(0,2);
bits1.set(4,6);
System.out.println(bits1); //110011
BitSet bits2 = BitSet.valueOf(new long[] {1,1,0,0,1,1}); //inline
System.out.println(bits2);
Run Code Online (Sandbox Code Playgroud)
有了这个代码,我试图复制相同的位集合是在BITS1,在BITS2.问题如下:打印和值不同.我设置的BitSet是110011.第一个打印出{0,1,4,5}并且它是正确的,因为这是用索引打印BitSet的"好方法",第二个打印出{0,64, 256,320}.你可以看到第二个是错的.我很确定内联初始化是错误的,但我无法弄清楚如何解决这个问题.
我知道我可以用多种语言编写CGI,最多的是C和Perl.但为什么我必须在Perl或C中编写它?有什么区别,什么是(最终)最好和最安全的解决方案?